Logger.Write vs LogEntry

Topics: Exception Handling Application Block, General discussion, Logging Application Block
Mar 25, 2008 at 3:51 PM
Hi,
Surely i am getting this all wrong,but could somebody point to me why should I use LogEntry when I could easily use Logger.Write with all the overloads?

Basically I cannot find a scenario where Creating a logEntry is needed rather than using the Logger directly.

Am I missing the obvious?

Thanks a lot
Mar 25, 2008 at 4:29 PM
Logger.Write() overloads are a kind of helping methods over LogEntry class to simplify logging usage and get rid of creating LogEntry manually. The same time Logger creates and uses LogEntry internally.

One of the possible ways to use LAB is deriving from LogEntry with your own entry class and then Logger.Write( LogEntry entry ) is a way to put it to the listener. For instance, if you created the new entry with new properties like UserName etc you already cannot use Logger.Write() methods because they don't populate these fields. In my experience we always create new entry classes for logging as well as we create the helper class similiar to Logger which uses our own entry class.

-
Thanks, Leonid
Mar 25, 2008 at 5:41 PM

Thanks for your reply.Not sure if you are refering to Exetended properties ,if so in the 5th overload of Logger.Write you can pass a IDictonary of properties.If that is what you meant I really cannot see the diff.

Thanks again
Mar 26, 2008 at 11:55 AM
Yes, there are Extended properties you can populate to log additional information. But you see you should do this each time you write a log entry before you call Logger.Write method. Using your own LogEntry class you can delegate this to it and don't bother anymore. Let's think of DataAccessLogEntry, AuditLogEntry etc.