Logging Application Block Basics

Topics: Logging Application Block
Jun 12, 2007 at 4:01 PM
Edited Jun 12, 2007 at 5:01 PM
Hi Group,

Our organization is planning to use Logging Application block for all the .NET projects running, but before that we are searching for some answers related to it.

First: where I can find the internals of Logging application block 2.0/3.0.

I need answers for the questions like: (I know asnwers to few, but I am not sure)

1. What best practices have followed in the implementation of logging application block? (Are they documented some where?)

2. Is buffered writing is supported by this block?

3. Does it write synchronously or asynchronously to the specified destination?

Like, let's say I am writing the log in the database then do I have to wait for completion of logging process or it is done asynchronously, so does my current thread do this for me or logging is handled by a separate thread?

4. Any other benefits I get by using the logging application block?
Why shouldn't I go for Log4Net or my own logger and use the enterprise library Logging Application Block?

5. Where could I find some code snippets for
a. using MSMQ with Logging application block
b. Database logging
c. Sending E-mails <Tried this but didnt worked>

Any clue or even a link addressing these issues will be a great help

Anup Daware
Jun 12, 2007 at 4:41 PM
Edited Jun 12, 2007 at 5:00 PM
Few Answers I already know:

Q: Is it Asynchronous?
A: No its is not, while writing to Database, Flat files, sending e-mails etc. To do it in asynchronous way you have to use MSMQ
My Concerns: How do you justify the LAB (Logging Application Block) on being Asynchronous? If I write my own Logger I can easily make it Asynchronous. so why it is not followed in LAB?

Q: Is buffered writing is supported
A: No its not. As it is not synchronous main thread is responsible for logging, so internally no buffering is implemented
My Concern: Logging is not a real-time task, so a thread with low priority can be used to log the entries buffered in some data structure.

Comment on MSMQ:
Only way to log asynchronously is to use MSMQ, but can I use MSMQ with all types of logging like flat file, e-mails, databases and windows event logs?
Also, are there any overheads of using MSMQ? Is there any example demonstrating use of MSMQ with LAB?

You must be thinking why am I going into negatives of LAB, but that’s because I want to talk in favor of LAB in front of several hungry technically very sound people and they are certainly going to shoot questions like these towards me and there I want to defend the Logging Application Block.

Please let me know if there is any mistake in the points raised by me. If anything I have written is incorrect.
So all the questions in first post with all the concerns mentions in this one are still open!!
I really expect some answers to my questions here after searching on net for long and posting on several forums.

Waiting for your valuable responses...
Jun 13, 2007 at 3:07 PM
Using MSMQ and the DistributorService you can log messages to any TraceListener. Thus you get asynchronous-like logging to e-mails, databases, EventLog, etc.

There was a discussion of log4net vs. Logging Application Block here that may help.




David Hayden
Microsoft MVP C#
Jan 30, 2008 at 6:49 PM

I have a simple solution for the asynchronous logging. @ http://systematically.blogspot.com/2008/01/asynchronous-logging-using-logging.html

I do not have the option of using MSMQ. So I came up with this solution of making the calls to the Logging application block asynchronous.

  • Saravanan Kanagaraj
Feb 4, 2008 at 7:34 PM
I read that when using the msmq tracelistener, you must use the binary formatter - on both the client side config file and the server side config file. So the message that lands in the queue is in binary, but what do you do then? Do you tack on another tracelistener, like a FlatFile tracelistener?

By the way I have tried that and got very bizarre results. See my recent post titled ""Using the Distributor Service".