How to use TraceSource.TraceEvent in a ASP.NET C# web application

故事扮演 提交于 2019-12-13 02:06:11

问题


I am required to use TraceSource.TraceEvent in an web application I am developing, after reading this and this msdn links

I am working on a project that is already built, I am making changes to it and updating it.

This is how my web.config is defined.

<system.diagnostics>
<sources>
    <listeners>
    <clear/>
    <add name="xml"/>
  </listeners>
</sources>

<sharedListeners>
  <add name="xml" type="System.Diagnostics.XmlWriterTraceListener"
                           traceOutputOptions="Callstack,LogicalOperationStack,ProcessId"
                           initializeData="C:\logs\Test.svclog"/>
</sharedListeners>

<trace autoflush="true" />

 </system.diagnostics>

The code that I am trying to use

var traceSource = new TraceSource("TraceSourceName");
traceSource.TraceEvent(TraceEventType.Error, 2, "Hello World !");

But no logging is done to Test.svclog file, I have created an empty file Test.svclog under the C:\logs\ folder.

Please help me out on this.


回答1:


I think you forgot to close your source.

Just modify your code to this

var traceSource = new TraceSource("TraceSourceName");
traceSource.TraceEvent(TraceEventType.Error, 2, "Hello World !");
traceSource.Close();



回答2:


You can adjust your source section with this post on msdn

http://msdn.microsoft.com/en-us/library/ms228984(v=vs.90).aspx



来源:https://stackoverflow.com/questions/11239541/how-to-use-tracesource-traceevent-in-a-asp-net-c-sharp-web-application

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