【问题标题】:NLog - ASP.Net Web API TracingNLog - ASP.Net Web API 跟踪
【发布时间】:2013-02-02 00:47:59
【问题描述】:

尝试使用 NLog 进行一些基本的 ASP.NET Web API 跟踪。

经过大量搜索,我能找到的唯一文档在这里:http://nlog-project.org/2010/09/02/routing-system-diagnostics-trace-and-system-diagnostics-tracesource-logs-through-nlog.html

以上内容不适用于 Web API,但我已尝试对其进行调整,问题似乎出在我的 Web.Config 中:

<system.diagnostics>
    <sources>
      <source name="System.Web.Http.ApiController" switchValue="All">        
        <listeners>
          <add name="nlog" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="nlog" type="NLog.NLogTraceListener, NLog" />
    </sharedListeners>
  </system.diagnostics>

任何想法为什么它不起作用或参考示例?

【问题讨论】:

    标签: asp.net-web-api nlog


    【解决方案1】:

    是的,我写过一篇文章,介绍如何将 NLog 实现为 Web API 的ITraceWriter 提供程序。

    它是针对 Web API RC 编写的,但它也可以在 RTM 上正常工作:http://www.strathweb.com/2012/06/using-nlog-to-provide-custom-tracing-for-your-asp-net-web-api/

    GitHub 上还有一个示例,作者是 Dave Bettin - https://github.com/dbettin/webapi.nlog

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-13
      • 2021-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多