In this article, I am going to show you how Logging Application Block are used for logging the information to different source.
See the below steps.
Step 1. Download the Enterprise Library 5.0, from the below url
Step 2. Install the Enterprise Library once downloaded.
Step 3. Once install successfully, when you open the web/window application and write click on config file, you can see the below menu(Edit Enterprise library..) to edit the config file.
Click on the menu(Edit Enterprise library..) to edit the config file.
Step 4. Once click you can see the below screen
now click on the Blocks menu and select Logging Setting to add Logging application block.
Once click on Add Logging Setting you can see the below screen.
Step 4. Just save the config file by clicking File->Save.
And add the below code in your program and execute the code, by default it log the message in the Event Log.
LogEntry logEntry = new LogEntry();
logEntry.EventId = 200;
logEntry.Priority = 1;
logEntry.Message = “Error Occured”;
logEntry.Severity = TraceEventType.Error;
After executing this code you can check the Event Log and see the message.
Log message in the Text File
Step 5. Click on the plus sign in front on Logging Target Listeners and click on the Add Flat File Trace Listener.
– Select Formatter to Text Formatter in the Flat file Trace Listener,
– Select Listeners Name to Flat File Trace Listener in General and Logging Error & Warning Section.
Once save the config file, logging will be started at Text file.
Using Enterprise Library, without changing code the log has been maintained to either Event Log, Flat file or Email etc. using this library message can be log in different source as below..
– The event log
– An e-mail message
– A database
– A message queue
– A text file
– A WMI event
– Custom locations using application block extension points
It simplify the life of programmer to use common and standard function for logging message by maintaining consist approach the practice.