Logging During Development and Runtime
Explore logging in C# using Debug and Trace classes to capture events during development and runtime. Understand how to configure trace listeners for outputs like console and text files. Gain practical experience by writing, running, and analyzing logs to improve debugging and monitoring of applications.
Once we believe all the bugs have been removed from our code, we will compile a release version and deploy the application so people can use it. But no code is ever bug-free; unexpected errors can occur during runtime.
End users are notoriously bad at remembering, admitting to, and accurately describing what they did when an error occurred. We should not rely on them accurately providing useful information to reproduce the problem so that we can understand what caused the problem and then fix it. Instead, we can instrument our code, logging events of interest.
Understanding logging options
.NET includes some built-in ways to instrument our code by adding logging capabilities. But logging is where third parties have created a rich ecosystem of powerful solutions extending what Microsoft provides. We cannot make specific recommendations because the best logging framework depends on our needs. Some common ones are in the following list:
Apache log4net
NLog
Serilog