Best. Logger. Ever.

Logging is one of those “system” components that always seems to either be left out or way over-engineered (glares at Microsoft’s Enterprise Application Blocks). Today, I’d like to introduce you to a logging framework that’s everything it needs to be and nothing it doesn’t.

The .Net Logging Framework from The Object Guy is powerful enough to handle any of your logging needs, but simple and painless to use.  Here’s a relatively complicated example — we’re going to log to three logging sources to demonstrate how easy it is to set up.  In most cases, of course, you’ll log to only one or two sources:

/* first instantiate some basic loggers */
Logger consoleLogger = TextWriterLogger.NewConsoleLogger();
Logger fileLogger = new FileLogger("unit_test_results.log");
Logger socketLogger = new SerialSocketLogger("localhost", 12345);

/* now instantiate a CompositeLogger */
logger = new CompositeLogger();

/* add the basic loggers to the CompositeLogger */
logger.AddLogger("console", consoleLogger);
logger.AddLogger("file", fileLogger);
logger.AddLogger("socket", socketLogger);

/* now all logs to logger will automatically be sent
to the contained loggers as well */

/* logging is a one-liner */
logger.LogDebug("Logging initialized.");

When you download this logger, you’ll get all the source code, including a socket reader to catch the logs thrown by the socketLogger in the example above.  Extending the logger is a piece of cake, too, so you could build yourself a WCF Logger, for instance, in no time flat.

You’ll note the lack of config file-driven settings in the example above — this is purely intentional.  You can decide if you want to make any of these settings configurable, and do so in the format you’re comfortable with, so you don’t need to try to get your config files to conform to whatever format your logger insists on using.  This small simplification can be a big time-saver for simple apps, debugging / test harness apps, and so on.

12 thoughts on “Best. Logger. Ever.

  1. Hello David,

    you might also want to look into our .NET logging tool SmartInspect:

    http://www.gurock.com/smartinspect/

    The big difference to the logging framework you mentioned is the powerful log viewer and analysis tool that we ship with SmartInspect. We also have very flexible log protocols and logging options that aren’t part of the framework you mentioned. FYI SmartInspect can be configured with just one line of code.

    Thanks,
    Dennis

    • That does look interesting (based on a quick glance). I’ll try to find some time to kick the tires. I like the router idea – I think that’s an important concept for a product like this. Do you have a way to do custom log writers, too (ie, logging to files / DB tables / etc.)?

        • You are comparing here a $5-$49 solution (the logging framework from The Object Guy) to a $299 up to many-thousand-dollar solution (yours). Of course your stuff has more features, but I do not think the comparison is fair. We’re talking basically free hight quality software vs expensive commercial software. Can be compared, but not fair IMO.

          • Price is certainly a factor – true. But if you look at the time & energy that could potentially be spent developing equivalent functionality, $299 could end up being a bargain. Logging, like many other infrastructure bits, is a function that varies a lot from application to application. Some apps get by just fine with minimal (or zero) logging, while others need more advanced capabilities.

            I’m sure that if people are comparing these two products, they’re going to include price as a factor, but hopefully, they’re also looking at their requirements carefully enough to understand whether the functionality they’re getting is worth the price. Both of these products are competing in the same space; one’s got a price advantage, and the other has more features. What’s the harm in comparing the two?

          • I hope it’s okay for me to chime in. :)

            I encourage people to make the comparison. I think it’s fair to compare features / prices. One thing that isn’t fair, though, is the erroneous information SmartInspect has on its comparison page on its web site. There are many features they inaccurately claim my framework doesn’t support. That’s especially not fair to people who are trying to make a decision.

            I brought this to Dennis’s attention over a year ago. After reading this thread, I reminded him again earlier today. Hopefully he will rectify the situation.

  2. Hello David,

    you might also want to look into our .NET logging tool SmartInspect:

    http://www.gurock.com/smartinspect/

    The big difference to the logging framework you mentioned is the powerful log viewer and analysis tool that we ship with SmartInspect. We also have very flexible log protocols and logging options that aren’t part of the framework you mentioned. FYI SmartInspect can be configured with just one line of code.

    Thanks,
    Dennis

    • That does look interesting (based on a quick glance). I’ll try to find some time to kick the tires. I like the router idea – I think that’s an important concept for a product like this. Do you have a way to do custom log writers, too (ie, logging to files / DB tables / etc.)?

        • You are comparing here a $5-$49 solution (the logging framework from The Object Guy) to a $299 up to many-thousand-dollar solution (yours). Of course your stuff has more features, but I do not think the comparison is fair. We’re talking basically free hight quality software vs expensive commercial software. Can be compared, but not fair IMO.

          • Price is certainly a factor – true. But if you look at the time & energy that could potentially be spent developing equivalent functionality, $299 could end up being a bargain. Logging, like many other infrastructure bits, is a function that varies a lot from application to application. Some apps get by just fine with minimal (or zero) logging, while others need more advanced capabilities.

            I’m sure that if people are comparing these two products, they’re going to include price as a factor, but hopefully, they’re also looking at their requirements carefully enough to understand whether the functionality they’re getting is worth the price. Both of these products are competing in the same space; one’s got a price advantage, and the other has more features. What’s the harm in comparing the two?

          • I hope it’s okay for me to chime in. :)

            I encourage people to make the comparison. I think it’s fair to compare features / prices. One thing that isn’t fair, though, is the erroneous information SmartInspect has on its comparison page on its web site. There are many features they inaccurately claim my framework doesn’t support. That’s especially not fair to people who are trying to make a decision.

            I brought this to Dennis’s attention over a year ago. After reading this thread, I reminded him again earlier today. Hopefully he will rectify the situation.

Comments are closed.