User1253338400 posted
Hi ,
In my app I have logging , but I would like to limit what I log. So foir example if I have a setting in web.config to log the rrrors or information.
In my web.config file I have the following:
<system.diagnostics>
<trace autoflush="true"/>
<sources>
<source name="MyLogFileSource" switchValue="Error">
<listeners>
<remove name="Default"/>
<add name="MyLogFileListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="iMyLogFileOrder.log"
traceOutputOptions="DateTime">
</add>
</listeners>
</source>
I call a number of statements in my applications
So for example
try{
... some code
TraceSource LogFile = new TraceSource("MyLogFileSource", SourceLevels.All);
LogFile.TraceInformation("TEST TO LOG ONLY ERRORS THIS SHOULD NOT BE LOGGED");
.. some more code runs and exception happens here. So it falls through to the catch .
}
Catch Exception (ex) {
LogFile.TraceEvent(TraceEventType.Error, 0, "Error MyLogFileSource: ");
LogFile.TraceData(TraceEventType.Error, 0, ErrorMessage(ex));
}
Since the web.config is configured to error , I would have thought only the error would be logged and not the Information ,
"TEST TO LOG ONLY ERRORS THIS SHOULD NOT BE LOGGED"
Is the Web config configured correctly for the trace type ?
Would it log an exception regardless of the setting ?
Thanks