Click here to Skip to main content
13,345,954 members (57,715 online)
Click here to Skip to main content
Add your own
alternative version


94 bookmarked
Posted 4 Dec 2006

EZLogger - drop-dead easy logging

, 22 Mar 2007
Rate this:
Please Sign up or sign in to vote.
A lightweight .NET logging component.


EZLogger is an object that provides basic logging facilities to your application. EZLogger is a lightweight alternative to more feature-rich logging subsystems such as Log4Net and XQuiSoft Logging, both of which are excellent logging mechanisms. I wrote EZLogger because my application's logging needs were simple and I wanted to keep my app's footprint small. I hope you find EZLogger useful and welcome your suggestions.


EZLogger writes log messages to a text file. The log file can be appended to, or a new one created when EZLogger is initialized. Log messages include a timestamp, severity and message text. Logging can be paused and resumed at any time. EZLogger's logging level (i.e. severities of interest) can be changed at run time to filter out unwanted messages. EZLogger is thread safe and can be used to log the activity of multiple threads.

EZLogger supports any combination of these severity levels:
  • Debug - trace and debug messages
  • Info - informational messages
  • Success - success messages
  • Warning - warnings
  • Error - error messages
  • Fatal - fatal errors
  • All - all messages

How to use EZLogger

You use EZLogger by creating a new instance, starting the logger, and calling one of the various logging methods. When you're done using the logger, you stop it as shown below.
// Create and start the logger
uint logLevels = (uint) EZLogger.Level.All;
EZLogger logger =
  new EZLogger ("C:\\EZLoggerTester.log",  // log filename
                false,                     // don't append
                logLevels);                // log levels of interest
bool bStatus = logger.Start();

// Write log messages
logger.Info ("An informational message");
logger.Warning ("A warning");
logger.Fatal ("A fatal error has occured");

// Stop logging

This code fragment produces the following log file.

12/4/2006 4:38:26 PM  I: An informational message
12/4/2006 4:38:26 PM  W: A warning
12/4/2006 4:38:26 PM  F: A fatal error has occur

The Pause() and Resume() methods can be used to temporarily suspend and restart logging.

// Starting long, boring operation

The Levels property can be set to restrict logging to message severities of interest.

// Only interested in errors and debug msgs
logger.Levels = (uint) (EZLogger.Level.Error | EZLogger.Level.Debug);
logger.Info ("...");   // won't be logged
logger.Error ("...");  // will be logged

How it works

Starting EZLogger causes it to maintain a reference to a StreamWriter. Calls to log messages invoke StreamWriter.WriteLine() which causes formatted text to be written (and flushed) to the log file. Messages are filtered based on the object's LogLevel property. EZLogger's methods are synchronized by marking their bodies as critical sections (using the lock keyword).

Revision History

  • 22 Mar 2007
    Added GetMessageCount() method to retrieve the number of messages logged. Thanks to John Tibbits for the suggestion!
  • 5 Dec 2006
    Added explicit Resume() method instead of overloading the behavior of Start().
    Added ability to filter on arbitrary severity levels.
  • 4 Dec 2006
    Initial version.


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


About the Author

Ravi Bhavnani
Technical Lead
Canada Canada
Ravi Bhavnani is an ardent fan of Microsoft technologies who loves building Windows apps, especially PIMs, system utilities, and things that go bump on the Internet. During his career, Ravi has developed expert systems, desktop imaging apps, marketing automation software, EDA tools, a platform to help people find, analyze and understand information, trading software for institutional investors and advanced data visualization solutions. He currently works for a company that provides enterprise workforce management solutions to large clients.

His interests include the .NET framework, reasoning systems, financial analysis and algorithmic trading, NLP, HCI and UI design. Ravi holds a BS in Physics and Math and an MS in Computer Science and was a Microsoft MVP (C++ and C# in 2006 and 2007). He is also the co-inventor of 3 patents on software security and generating data visualization dashboards. His claim to fame is that he crafted CodeProject's "joke" forum post icon.

Ravi's biggest fear is that one day he might actually get a life, although the chances of that happening seem extremely remote.

You may also be interested in...

Comments and Discussions

Questionmodify version - auto generate log filename by today date Pin
woongs.bang13-Feb-13 20:57
memberwoongs.bang13-Feb-13 20:57 
QuestionGreat and Simple! MDI Form Question... Pin
Travis Hamera29-Dec-11 20:47
memberTravis Hamera29-Dec-11 20:47 
AnswerRe: Great and Simple! MDI Form Question... Pin
Ravi Bhavnani30-Dec-11 3:35
memberRavi Bhavnani30-Dec-11 3:35 
GeneralRe: Great and Simple! MDI Form Question... Pin
Travis Hamera31-Dec-11 8:33
memberTravis Hamera31-Dec-11 8:33 
GeneralRe: Great and Simple! MDI Form Question... Pin
Ravi Bhavnani31-Dec-11 8:46
memberRavi Bhavnani31-Dec-11 8:46 
GeneralMy vote of 5 Pin
polczym23-Oct-11 4:11
memberpolczym23-Oct-11 4:11 
GeneralRe: My vote of 5 Pin
Ravi Bhavnani26-Dec-11 10:31
memberRavi Bhavnani26-Dec-11 10:31 
GeneralWindow CE Pin
Member 23087665-Aug-10 6:01
memberMember 23087665-Aug-10 6:01 
GeneralRe: Window CE Pin
Ravi Bhavnani5-Aug-10 7:46
memberRavi Bhavnani5-Aug-10 7:46 
GeneralRe: Window CE Pin
Member 23087665-Aug-10 15:57
memberMember 23087665-Aug-10 15:57 
AnswerRe: Window CE Pin
Ravi Bhavnani5-Aug-10 16:28
memberRavi Bhavnani5-Aug-10 16:28 
GeneralRe: Window CE Pin
Member 23087665-Aug-10 19:38
memberMember 23087665-Aug-10 19:38 
GeneralSimple and good Pin
mannabaron29-May-07 8:38
membermannabaron29-May-07 8:38 
GeneralRe: Simple and good Pin
Ravi Bhavnani29-May-07 8:44
memberRavi Bhavnani29-May-07 8:44 
QuestionRolling File Appender ? Pin
mejax2-Apr-07 9:21
membermejax2-Apr-07 9:21 
AnswerRe: Rolling File Appender ? Pin
Ravi Bhavnani2-Apr-07 9:24
memberRavi Bhavnani2-Apr-07 9:24 
Not without modifications, since EZLogger writes directly to the file (vs. keeping a rolling log in memory).


This is your brain on Celcius
Home | Music | Articles | Freeware | Trips

QuestionRe: Rolling File Appender ? Pin
mejax3-Apr-07 7:55
membermejax3-Apr-07 7:55 
AnswerRe: Rolling File Appender ? Pin
Ravi Bhavnani3-Apr-07 8:25
memberRavi Bhavnani3-Apr-07 8:25 
QuestionLevel Assignment question Pin
arrivederci27-Mar-07 3:33
memberarrivederci27-Mar-07 3:33 
AnswerRe: Level Assignment question Pin
Ravi Bhavnani27-Mar-07 3:40
memberRavi Bhavnani27-Mar-07 3:40 
GeneralRe: Level Assignment question Pin
arrivederci27-Mar-07 4:08
memberarrivederci27-Mar-07 4:08 
AnswerRe: Level Assignment question Pin
Ravi Bhavnani27-Mar-07 6:09
memberRavi Bhavnani27-Mar-07 6:09 
GeneralRe: Level Assignment question Pin
arrivederci27-Mar-07 8:44
memberarrivederci27-Mar-07 8:44 
GeneralSuperb Pin
leonvd12-Dec-06 0:03
memberleonvd12-Dec-06 0:03 
GeneralRe: Superb Pin
Ravi Bhavnani12-Dec-06 3:05
memberRavi Bhavnani12-Dec-06 3:05 

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 | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 22 Mar 2007
Article Copyright 2006 by Ravi Bhavnani
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid