简体   繁体   English

创建自定义事件日志

[英]Create a custom event log

How do I programmatically check for/create a custom event log to be viewed in Windows XP/2003 event viewer? 如何以编程方式检查/创建要在Windows XP / 2003事件查看器中查看的自定义事件日志?

Right now I can create entries in the 'Application' log but want to have custom logs for my various applications. 现在我可以在“应用程序”日志中创建条目,但希望为我的各种应用程序提供自定义日志。

I am using C# - .NET Framework 3.5 我正在使用C# - .NET Framework 3.5

The System.Diagnostics.EventLog class in the framework has a CreateEventSource method... 框架中的System.Diagnostics.EventLog类有一个CreateEventSource方法......

 EventLog.CreateEventSource(source, logName);

Be aware that to create a new eventLog (or eventLog Source) requires a higher level of authority (WIndows Access Control List (ACL) permissions), than does simply writing to the log, and normally, this access level is not available to most applications... So you will need to make sure your deployment process or deployment msi does the event log/source creation at that time... when the process installing the app should have sufficient permissions. 请注意,创建新的eventLog(或eventLog Source)需要更高级别的权限(WIndows访问控制列表(ACL)权限),而不是简单地写入日志,通常,大多数应用程序都无法使用此访问级别...因此,您需要确保部署过程或部署msi在那时创建事件日志/源代码...当安装应用程序的进程应具有足够的权限时。

You need to create a custom event log, as described here . 您需要创建一个自定义事件日志,描述在这里 If you are using log4net for logging (recommended), you can configure an EventLogAppender as in the following example: 如果使用log4net进行日志记录(推荐),则可以配置EventLogAppender如以下示例所示:

<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
    <applicationName value="MyApp" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %-5level %logger - %message%newline" />
    </layout>
</appender>

You need to specify the Log property of the EventLog object. 您需要指定EventLog对象的Log属性。

Documentation can be found here: 文档可以在这里找到:

http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.log.aspx http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.log.aspx

Here is an example of a custom Event logger for .Net 3.5 and 4.0. 以下是.Net 3.5和4.0的自定义事件记录器示例。

Log4Net is also a great tool for this, in my case I was building a lib and the client's calling program did not have log4net.. Log4Net也是一个很好的工具,在我的情况下,我正在构建一个lib,而客户端的调用程序没有log4net。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM