Basic tracing in .Net Framework
Please note this is not recommended for production. For production, use other products such as Azure Application Insights
- Quick debugging of .Net Framework applications (legacy) in higher environments by turning the logging on in the configuration file.
- Below goes the Tracing code in the application.
Trace.TraceError("This is a trace.traceerror");
Trace.TraceInformation("This is a trace.traceinformaton");
Trace.TraceWarning("This is a trace.tracewarning");
Unfortunately developers like me needs to maintain legacy code bases. Enjoy ILogger if you are in .Net Core / .Net 5/6 world.
- This is for simple tracing purpose with Trace class. Though TraceSource is powerful, that require more code.
Personally I don't recommend TraceSource as I have experienced performance issues with it. I recommend Windows OS level ETW or dedicated instrumentnation technologies such as Azure Application Insights.
If we are in debugging higher level environments and we don't have access to production instrumentation, but have permission to update the application configuration, this is useful. Don't ask why. Welcome to legacy Enterprise world.
switches require application to check switch before logging. That cannot be simply done when using static methods of Trace class. Use TraceSource to get that feature.
- There is a caution given in documentation about it as its not thread-safe. It leads to resource contention due to locks Eventually performance degradation. Read the Docs
- It is mainly intended to use with TraceSource tracing. Not good with static methods of
Trace
class
ReadTheDocs. It doesn't seems good at correlation.'
- Yes. Though it is not in this sample, it is very much possible.
- It does not output optional trace data.
- It may require permission to write to EventLog.