Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging Framework, a good idea?

First of all, apologies for the subjective sounding title. This is intended as a direct question.

At present I am working on a suite of tools:

  • A C# Windows Service, to primarily maintain an Oracle database.
  • A C# Windows Service, (which will be used on multiple node sites) to process content of the database.
  • An ASP.NET web interface to facilitate management of the overall "system"

Currently the tho Windows Services have been developed as Console Applications (to ease debugging/development) and I am in the midst of converting these to Services. After testing for a couple days now with these services, I'm finding that I would like to increase the granularity of my logging. I'm finding that I miss Console.WriteLine() and I would like to provide an alternate log source like a flat-file for this type of output. This has lead me to think, "Should I be using a framework, or have I got enough?"

The reason I have mentioned the aspects I am developing is to provide insight to my situation. A "Core" DLL has been created, common across all components, abstracting the interaction layer between the applications and database. It is within this DLL that a class has been created which will attempt to "log to a table in the database" else on fail "log to local Event Log". This is it, that's the extent of logging.

Throughout the aforementioned tools, there are multiple instances of logging not dissimilar to:

Log.LogError("Code", e.Message + "\n" + e.StackTrace);

Although quite basic, this method does make use of reflection to Identify the source of the error.

My Question

Looking at my current logging solution it appears "sufficient" in terms of what it does and how it is integrated with all my solutions. However, I've been looking at logging frameworks (Notably log4net) and their features impress me. The ability to, if needed in the future, add another output format (such as an SMTP server) sounds kind of cool to me! :)

What I would like to know are the benefits of moving to a framework (like log4net)? The extent of how much I will have to adapt my code? Whether or not I am just looking at the greener grass on the other side? And finally, but probably most importantly, am I doing the right thing? Should I just add the ability to my Log class to "LogDebug" and be done with it? The last thing I would want to do is completely overhaul my suite, just for a "basic" feature, but if there are other benefits (to design, reliance, good practice? etc.) I'm interested.

Thanks,

like image 678
Mike Avatar asked Oct 22 '09 09:10

Mike


1 Answers

Yes. Using an existing, proven logging framework (such as Log4net) is a good idea.

Log4Net is configurable at runtime (great for tracking down issues in production code).

As a commenter pointed out, it's also very simple to use.

like image 132
Mitch Wheat Avatar answered Oct 21 '22 15:10

Mitch Wheat