使用 NLog 记录到特定事件源

发布于 2024-12-29 17:39:41 字数 802 浏览 2 评论 0原文

我可以使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾挽 2025-01-05 17:39:41

您应该像这样设置目标的源和日志:

<target xsi:type="EventLog" 
   name="eventlog" 
   layout="${message}"
   source="custom_source" 
   log="custom_log"/>

You should set target's source and log like this:

<target xsi:type="EventLog" 
   name="eventlog" 
   layout="${message}"
   source="custom_source" 
   log="custom_log"/>
想念有你 2025-01-05 17:39:41

你尝试过跑步吗

InstallNLogConfig.exe c:\path\to\NLog.config

部署NLog配置文件

InstallNLogConfig.exe 现已包含在最新的 NuGet 包中

Have you tried to run

InstallNLogConfig.exe c:\path\to\NLog.config

As described in Deploying NLog configuration files ?

InstallNLogConfig.exe is now included in the latest NuGet package.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文