EventLogChannel.h 2.9 KB

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