In this tip, a simple C# project is provided to show the use of '
Vi.Logger': a class designed to define a standardized but flexible way to manage the log of messages. The design of this class is made having in mind Log4Net, but this is not a constraint.
Vi.Logger' exposes the classic methods to log messages: Debug; Info; Warn; Error; Fatal, but none of these writes anything. The responsibility of this class is to provide a fully featured architecture with:
Last but not least characteristic is that, this 'architecture', wrapping the object provided as a parameter, by the method '
SetLogger', makes it not necessary 'to adorn' the latter with all the infrastructure that is required by professional code. In other words, the object provided to the method '
SetLogger' is made to be used by the code (the
Vi.logger' class) and not by the developers, so no infrastructure is needed. To provide a good enough structure isn't a challenging task but it is resource-consuming. (For example, the class 'Vi.Logger' despite its simplicity is made with more than 400 lines of code.)
In the project, you can find also the user control: List4Net,
Listview and specialized to 'intercept' messages and show them on screen.
List4Net can provide a quick access to messages during the development phase, an overview over the logs in production.
(I used this control to monitor, in production, a TCP/IP socket designed to receive tens of million records a day. For this reason, the control intercepts messages only when it is active, in that way, it does not add any overload on the production server.)
Basic knowledge of C#
Using the Code
It is very simple. The only thing to do is download and run.
This project also comes with a detailed help file (documentation.chm).
Points of Interest
The advantages this solution bring are as follows:
- Removes the dependency on the specific logging tool adopted: It is not necessary to know how the log is performed. The way logs are 'written' can change at any time (file system; event viewer; DB;
ListView; Console; ...) .
- Sets a standard for the company: It is a common experience that every developer has his/her own "style" when writing logs. This shouldn't happen (especially in a well-structured company.)
- Simplicity: Log4Net is a very powerful tool: just 'plug and forget'. Its drawback is the 'configuration' (in my experience, making it run is a nightmare.) This class removes this problem.
- Easy to switch: The switch between the "destinations" (file system, Console, event log, DB, ... ) is very easy.
- 2nd October, 2016: Initial version
- Someone score this "Tip" 1. This is a faculty of the reader: nothing to say! May I ask why? (so I can apply the right correction and make this "Tip" better.)