Monday, January 27, 2014

Enterprise Library Logging Application Block




Background
Many applications, and especially large-scale systems, could benefit from a consistent approach to logging. To help, there are a number of logging libraries available to the .NET developer, such as Log4Net and NSpring.
It’s a part of Enterprise Library.
Help to get rid of all the complication of logging.
Basic idea of this is you are going to write some log entries in your code using a simple API with some meta information about the logged message. Then you are going to set up some configuration. configurations is going to be flexible.
Main benefit of Logging Application block is it’s allow you to use one single API to do your logging using log writer class.

Logging Block Flow

1)      Log writer API to write a log. It may be a string.
2)      Filter with values which only need to pass through.
3)      There are several kind of sources. It may consist with different kind of listeners.(can send your log msgs to db, a file, email etc.
4)      Some of listeners requre formatters.
From application perspective you only have to know about writing the log and Conf tool with enterprises application blog makes all the others.


Design consideration
·         Performance
·         Logging has a cost, it’s better to put lot of loggings in your application
·         Have to think about the design of actual logging strategy. 

Logging Options (don’t have to have theses)
  • Category - used to determine the routing of the LogEntry. Defult : General
  • Priority - used to filter Log Entries. Just a number. Defaults to -1 which indicates that the Minimum Priority should be used.
  • EventId – Just a generic ID. A value you can use to further categories Log Entries Defaults to 0 for a LogEntry and to 1 for a LogEntry implicitly created by Logger.Write).
  • Severity - indicates the severity of the Log Entry, e.g., Information, Warning, Error etc.
  • Title - a summary of the LogEntry.Message.
Demo
·         Create a console application
·         References -> Manage NuGet packages -> Install Enterprise Library – Logging Application Block

 


·         Then add App config file -> right click on app.config file and edit that using “Enterprise Library configuration”.






No comments:

Post a Comment