Logging and tracing are two titles for the exact same technique. The easy technique was utilized since the early days of computers. It only involves instrumenting a program to write output to be consumed afterwards.
This very simple technique is surprisingly strong. It May Be Used in scenarios in which a debugger fails:
Issues happening over extended intervals, can be hard to sew using a conventional debugger. Logs allow for comprehensive post-mortem review spanning extended intervals. By comparison, debuggers are restricted to real time investigation.
Multi-threaded software and distributed programs are often tough to debug. Attaching a debugger will alter behaviors. Detailed logs could be examined as needed to comprehend complex systems.
Issues in distributed programs may emerge from a intricate interaction involving many elements and it might not be sensible to link a debugger to each region of the system.
Many providers should not be postponed. Attaching a debugger frequently causes timeout failures.
Issues are not always foreseen. Logging and therefore are created for low elevation so that apps could always be recording if a problem happens.
.NET Core APIs
The System.Console, System.Diagnostics.Trace, and System.Diagnostics.Debug paths each provide similar printing design APIs suitable for logging.
The selection of which print design API to use is your decision. The main differences are:
Always enabled and writes to the console.
Useful for advice your client might have to view in the discharge.
Because it is the easiest approach, it is frequently used for short-term debugging. This debug code can be never checked into source control.
Writes to connected Listeners, by default the DefaultTraceListener.
Use this API when generating logs which are going to be allowed in most builds.
Writes into an attached debugger.
Use this API when generating logs which will be allowed only in debug builds.
These APIs are far more event oriented. As opposed to logging easy strings that they log event items.
EventSource is the principal origin .NET Core tracing API.
Available in most .NET Standard versions.
Only allows tracing serializable items.
Writes into the connected occasion listeners.
Included in .NET Core and as a NuGet bundle to get .NET Framework.
Allows in-process tracing of non-serializable items.
Includes a bridge allowing selected areas of logged items to be composed to a EventSource.
Provides a definitive method to discover log messages caused by a particular action or transaction. This item may be used to link logs across various providers.
System administrators anticipate fatal software error messages to look from the Windows Event Log.
The low-level APIs might not be the ideal selection for your logging needs. You might wish to take into account a logging framework.
The ILogger port was utilized to make a common logging port in which the loggers could be inserted via dependency injection.
For Example, to Enable you to create the best choice for your program ASP.NET Features support for a Choice of built-in and third party frameworks:
ASP.NET built in logging suppliers
ASP.NET Third-party logging suppliers
Logging related references
ASP.NET Logging offers an summary of the logging methods it supports.
The Exception.Message home is helpful for logging exceptions.
The System.Diagnostics.StackTrace course can be practical to provide heap info on your logs.
String formatting may shoot noticeable CPU processing period.
In performance critical software, it is Suggested that you:
Avoid a lot of logging when nobody is listening. Avoid constructing expensive logging messages by assessing if logging is enabled first.
Only log what is useful.
Defer elaborate formatting into the analysis phase.