In most enterprise applications, logging is as essential as any other business need. An internet banking site, for example, can't live without logs.
What is Logging?
In my view, an application log is a record of all events and operations on the model with the information needed to provide an audit trail.
The recorded information should be such that could be used to rollback and/or replay all or selected operations.
A good example of this concept is SQL Server’s transaction log.
What is Tracing?
Tracing, on the other hand, is a record of events in the application itself.
The recorded information can be used to track application behaviors and should never be critical to the business.
Still having in mind the SQL Server analogy, tracing is what SQL Server logs in the Windows
What is a Log Scope?
A log scope is scope of events and operations that need to be recorded as a unit.
A log scope can be the request/response of a web page to a web server, can be a call to a web service, can be retrieving some information from a database, etc.
What are the Prerequisites for a Log Scope?
- Possibility to join the current log scope if one exists
- Possibility to start a new log scope whenever wanted
- Independence of application layers
- Independence of the environment
- Independence of subscribers
- Have a header
- Have multiple details
The best usage pattern would be a proxy class that implements
IDisposable which would allow the use of
using (C#, VB) blocks, improving the code readability and maintainability.
using (LogScope log = new LogScope())
Using log as New LogScope()
Creating Log Scope Proxies
The creation of log scope proxy instances should be by means of instantiation of a class instance with the proxy set up parameters.
public LogScope(LogScope logScope);
public LogScope(object logHeader);
public LogScope(LogScope logScope, object logHeader);
public LogScope(object logMaster, bool requiresNew);
public LogScope(LogScope logScope, object logHeader, bool requiresNew);
''' Initializes a new log scope proxy that joins the current log scope, if one exists.
Public Sub New()
''' Initializes a new log scope proxy that joins a specified log scope, if one exists.