2

我使用 NLog Extended 的 AspNetBufferingWrapper 包装器在我的 web.config 中有以下目标

<wrapper-target type="ASPNetBufferingWrapper" name="aspNetBuffer">
    <wrapper-target type="PostFilteringWrapper" name="postFilter" defaultFilter="level >= LogLevel.Debug">
      <target-ref name="logDB" />
      <when exists="level >= LogLevel.Warn" filter="level >= LogLevel.Trace" />
    </wrapper-target>
  </wrapper-target>

目标引用在没有包装器或其他包装器的情况下工作。我有文档推荐的httpmodule

<httpModules>
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
  <add name="NLog" type="NLog.Web.NLogHttpModule, NLog.Extended" />
</httpModules>

我已经在 MVC3 项目中配置了 NLog.2.0.0.2000 和 NLog.Extended.2.0.0.2000。

我已经包含了 elmah 模块以指出该模块正在工作。经过搜索,我发现集成模式下的 IIS 7 使用 system.webServer 模块。我注意到 elmah 模块已经配置了这个部分,所以我包含 NLog.Extended 已经很好了。

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
      <add name="NLog" type="NLog.Web.NLogHttpModule, NLog.Extended" preCondition="managedHandler" />
    </modules>
  </system.webServer>

好吧,它也不好用......我已经在 Trace 模式下激活了内部 Nlog 记录器,我看到以下内容:

2013-03-19 16:06:58.2933 Trace Sending buffered events to wrapped target: PostFilteringWrapper Target[postFilter](AsyncWrapper Target[logDB](Database Target[logDB_wrapped])).
2013-03-19 16:06:58.2933 Trace Running PostFilteringWrapper Target[postFilter](AsyncWrapper Target[logDB](Database Target[logDB_wrapped])) on 0 events
2013-03-19 16:06:58.3053 Trace Filter to apply: (level >= Debug)
2013-03-19 16:06:58.3053 Trace After filtering: 0 events.

我不记得还能做什么/搜索。我错过了什么吗?

4

1 回答 1

0

The reason only the logfile from the AsyncWrapper are written, is because your ASPNetBufferingWrapper and AsyncWrapper has the same name. Also you File targets have the same name.

But this can only been seen when looking at your config file, http://pastebin.com/3cP83PWa posted on the NLog issues page

If you targets have unique names both files will be written.

于 2013-04-01T21:01:21.013 回答