Trace not working in C#
I have an ASP.NET application that I'm trying to write some logging info on. To do this, I wanted to use tracing. I believe I have it setup properly. In my web.config file, I have:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp"
extension=".cs"
compilerOptions="/d:TRACE"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="1" />
开发者_如何学Go</compilers>
</system.codedom>
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="c:\\logs\\mylog.log" />
<remove name="default"/>
</listeners>
</trace>
</system.diagnostics>
In my code, I have the following:
Trace.WriteLine("Test Trace");
Trace.Flush();
However, mylog.log never gets created. What am I doing wrong? Thank you,
Ensure that the app has the necessary security rights and permissions to access that folder/file. Also ensure the folder exists.
I believe in the interests of keeping an app running in times of trouble, if you misconfigure a trace listener like this the app will continue without error.
(Of course, it could also be that your logging code is never reached)
Doesn't look like you enabled tracing:
<trace enabled="true" ...
精彩评论