EventLogChannel.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // EventLogChannel.h
  3. //
  4. // Library: Foundation
  5. // Package: Logging
  6. // Module: EventLogChannel
  7. //
  8. // Definition of the EventLogChannel class specific to WIN32.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Foundation_EventLogChannel_INCLUDED
  16. #define Foundation_EventLogChannel_INCLUDED
  17. #include "Poco/Foundation.h"
  18. #include "Poco/Channel.h"
  19. #include "Poco/UnWindows.h"
  20. namespace Poco {
  21. class Foundation_API EventLogChannel: public Channel
  22. /// This Windows-only channel works with the Windows NT Event Log
  23. /// service.
  24. ///
  25. /// To work properly, the EventLogChannel class requires that either
  26. /// the PocoFoundation.dll or the PocoMsg.dll Dynamic Link Library
  27. /// containing the message definition resources can be found in $PATH.
  28. {
  29. public:
  30. EventLogChannel();
  31. /// Creates the EventLogChannel.
  32. /// The name of the current application (or more correctly,
  33. /// the name of its executable) is taken as event source name.
  34. EventLogChannel(const std::string& name);
  35. /// Creates the EventLogChannel with the given event source name.
  36. EventLogChannel(const std::string& name, const std::string& host);
  37. /// Creates an EventLogChannel with the given event source
  38. /// name that routes messages to the given host.
  39. void open();
  40. /// Opens the EventLogChannel. If necessary, the
  41. /// required registry entries to register a
  42. /// message resource DLL are made.
  43. void close();
  44. /// Closes the EventLogChannel.
  45. void log(const Message& msg);
  46. /// Logs the given message to the Windows Event Log.
  47. ///
  48. /// The message type and priority are mapped to
  49. /// appropriate values for Event Log type and category.
  50. void setProperty(const std::string& name, const std::string& value);
  51. /// Sets or changes a configuration property.
  52. ///
  53. /// The following properties are supported:
  54. ///
  55. /// * name: The name of the event source.
  56. /// * loghost: The name of the host where the Event Log service is running.
  57. /// The default is "localhost".
  58. /// * host: same as host.
  59. /// * logfile: The name of the log file. The default is "Application".
  60. std::string getProperty(const std::string& name) const;
  61. /// Returns the value of the given property.
  62. static const std::string PROP_NAME;
  63. static const std::string PROP_HOST;
  64. static const std::string PROP_LOGHOST;
  65. static const std::string PROP_LOGFILE;
  66. protected:
  67. ~EventLogChannel();
  68. static int getType(const Message& msg);
  69. static int getCategory(const Message& msg);
  70. void setUpRegistry() const;
  71. #if defined(POCO_WIN32_UTF8)
  72. static std::wstring findLibrary(const wchar_t* name);
  73. #else
  74. static std::string findLibrary(const char* name);
  75. #endif
  76. private:
  77. std::string _name;
  78. std::string _host;
  79. std::string _logFile;
  80. HANDLE _h;
  81. };
  82. } // namespace Poco
  83. #endif // Foundation_EventLogChannel_INCLUDED