NLog:无法写入事件日志
我无法使用 NLog 写入事件日志。我已经能够写入控制台和文件。我已在 NLog 中打开异常,但没有收到来自 NLog 的反馈。
这是我的 NLog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="true">
<targets>
<target name="console" xsi:type="Console" layout="${message}" />
<target xsi:type="EventLog" name="eventlog" layout="${message}" log="Application" source="aaaTest"/>
<target xsi:type="File" fileName="log.txt" name="file"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="eventlog,console,file" />
</rules>
</nlog>
在事件查看器中,我正在查看“事件查看器(本地)”> “Windows 日志”> “应用”。但是,我在日志中没有看到“aaaTest”(我定义的源)的实例。
I can't write to the event log with NLog. I've been able to write to the console and to a file. I've turned on exceptions in NLog and am receiving no feedback from NLog.
Here is my NLog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="true">
<targets>
<target name="console" xsi:type="Console" layout="${message}" />
<target xsi:type="EventLog" name="eventlog" layout="${message}" log="Application" source="aaaTest"/>
<target xsi:type="File" fileName="log.txt" name="file"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="eventlog,console,file" />
</rules>
</nlog>
In Event Viewer, I am looking at "Event Viewer (Local)" > "Windows Logs" > "Application". However, I see no instances of "aaaTest" (my defined source) in the log.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 nlog 论坛帖子
为了能够写入事件日志,应用程序必须注册为事件源。如果你以管理员身份运行 VS,这会自动发生。如果您创建安装程序并安装应用程序,它将被注册。
要将应用程序手动注册为事件源,我使用以下脚本:
另请参阅:https ://github.com/NLog/NLog/wiki/Eventlog-target#notes
From nlog forum post
To be able to write to the EventLog an application must be registered as an event source. If you run VS as admin this happens automatically. If you create an installer and install your application it gets registered.
To register an app manually as event source I use the following script:
See also: https://github.com/NLog/NLog/wiki/Eventlog-target#notes