Simple tracing in ASP.NET 4

断了今生、忘了曾经 提交于 2019-12-04 18:08:36

You need a little more configuration. This code block will log all errors to one file and all Information and ActivityTracing nodes to another. (This example is for WCF, you will need to set your names to whatever you need them to be.)

<system.diagnostics>
<sources>
  <source name="System.ServiceModel"
          switchValue="Information, ActivityTracing"
          propagateActivity="true" >
    <listeners>
      <add name="xml"/>
    </listeners>
  </source>
  <source name="System.ServiceModel.MessageLogging">
    <listeners>
      <add name="xml"/>
    </listeners>
  </source>
  <source name="ServiceFaultInfoTrace"
          switchName="sourceSwitch"
          switchType="System.Diagnostics.SourceSwitch">
    <listeners>
      <add name="ServiceFaultInfoTraceText" />
      <remove name="Default"/>
    </listeners>
  </source>
</sources>
<switches>
  <add name="sourceSwitch" value="Error"/>
</switches>
<trace autoflush="true" indentsize="4">
  <listeners>
    <add name="ServiceFaultInfoTraceText" />
  </listeners>
</trace>
<sharedListeners>
  <add name="xml"
       type="System.Diagnostics.XmlWriterTraceListener"
       initializeData="C:\log\Api-Traces.svclog" />
  <add name="ServiceFaultInfoTraceText"
       type="System.Diagnostics.TextWriterTraceListener"
       traceOutputOptions="DateTime"
       initializeData="C:\log\Api-Errors.txt" />
</sharedListeners>
</system.diagnostics>

The important nodes are the switchValue (and switchName) nodes. Set them to whatever level you want logged for the source.

http://msdn.microsoft.com/en-us/library/system.diagnostics.tracelevel.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!