使用 NLog 记录到特定事件源
我可以使用 NLog 记录 Windows 事件源。
但我想要的是编写一个特定的事件源:例如:MyEventSource
我的配置是:
<?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">
<targets>
<target name="eventlog" xsi:type="EventLog" log="MyEventSource" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="eventlog" />
</rules>
</nlog>
当我尝试记录任何内容时,MyEventSource 被创建,但日志消息被写入一般窗口 [7] 申请事件源而不是 MyEventSource .
更新:
<target name="eventlog" xsi:type="EventLog"
layout="${message}" log="custom_log" source="custom_source" />
没有区别
I can able to log windows event source using NLog.
But what i want is to write a specific event source: such as : MyEventSource
My config is:
<?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">
<targets>
<target name="eventlog" xsi:type="EventLog" log="MyEventSource" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="eventlog" />
</rules>
</nlog>
Well when i try to log anthing, MyEventSource is created but log message is written to general windows [7] applicantion event source not MyEventSource.
Update:
<target name="eventlog" xsi:type="EventLog"
layout="${message}" log="custom_log" source="custom_source" />
Make no difference
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该像这样设置目标的源和日志:
You should set target's source and log like this:
你尝试过跑步吗
如 部署NLog配置文件?
InstallNLogConfig.exe 现已包含在最新的 NuGet 包中。
Have you tried to run
As described in Deploying NLog configuration files ?
InstallNLogConfig.exe is now included in the latest NuGet package.