Click here to Skip to main content
13,900,082 members
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 2 Oct 2016
Licenced CPOL

Logger for Log4Net

, 4 Oct 2016
Rate this:
Please Sign up or sign in to vote.
Some solutions to the task of logging messages

Documentation on-line





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:

  • Overloads: All the methods have a different signature with a different set of parameters to choose from. There is also an 'embedded' Format method (like the String.Format). for example Vi.Logger.Info().Format("Hello {0}", "Word")

  • CompilerServices: All the methods can track information about the caller: file name; member name; line number (In my experience, this feature has proven to be VERY useful, if not the most useful.)
  • Abstraction: As said, this class does not implement any 'log strategy'. This is the responsibility of the object provided, as a parameter, by the method 'SetLogger'. (This makes the class easy to use and easy to change the way logs are stored.)
  • Documentation: All methods are fully documented with summaries and help file. In that way, IntelliSense and Help are enabled. This allows the use of the DLL (instead of the code) which improves the standardization.
  • public static: All the log methods are public static, then 'global' (to the solution) and 'ready to use'.

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,

derived to 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.)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Member 270861
Engineer ACME
United Kingdom United Kingdom
I like to find simple solution to general (software) problem.
Some I published here and hope you enjoy them


You may also be interested in...

Comments and Discussions

QuestionIndeed good point ... Pin
Tachyonx3-Oct-16 23:04
memberTachyonx3-Oct-16 23:04 
AnswerRe: Indeed good point ... Pin
Member 2708614-Oct-16 1:04
memberMember 2708614-Oct-16 1:04 
GeneralRe: Indeed good point ... Pin
Tachyonx4-Oct-16 1:33
memberTachyonx4-Oct-16 1:33 
GeneralRe: Indeed good point ... Pin
Member 2708614-Oct-16 5:47
memberMember 2708614-Oct-16 5:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190306.1 | Last Updated 4 Oct 2016
Article Copyright 2016 by Member 270861
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid