Logging Application Block 4.1 with ASP.NET MVC application

Topics: Logging Application Block
Jun 17, 2009 at 6:32 PM

Hello,

I'm trying to use EL 4.1 Logging Application Block with a new ASP.NET MVC application.

Please tell:
1. Default timestamp is in UTC, how to get timestamp in Local server timezone ?

2. For 'Rolling Flat File Trace Listener' if I set Filename property to invalid location (where file can not be created), Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write() method throws an exception.
   This occurs even if 'Special Source - Logging Errors and Warnings' has a VALID listener. Morever this exception is NOT logged to 'Special Source - Logging Errors and Warnings'.
   Please tell how to log invalid file location error and not throw exception.

2. How much is performance overhead of LAB as compared to ASP.NET Health Monitoring and log4net ?


Thank You.

Jun 18, 2009 at 10:12 AM

Hi,

For #1, please refer to this link: http://entlib.codeplex.com/Wiki/View.aspx?title=How%20can%20I%20change%20the%20timestamp%20format%20of%20my%20log%20entries%20to%20my%20local%20time%3f&referringTitle=Home

For #2, We'll investigate further on this one and get back to you.

For #3, I really can answer that because I'm not familiar with Health Monitoring and log4net but you can check out this post about comparison of log4net and LAB .

http://james.newtonking.com/archive/2007/06/05/enterprise-library-logging-vs-log4net.aspx

http://blogs.claritycon.com/blogs/don_peterson/archive/2006/01/30/184.aspx

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Jun 30, 2009 at 7:43 AM
Edited Jun 30, 2009 at 7:48 AM

Hi,

Going back to #2, As far as I've investigated, i found out that there is no easy way to get around thru this. calling the Logger.Write( ) throws exception because when it fails trying to create the file. One thing you can do is to modify the source code. On the FormattedTextWriterTraceListener.cs, on the method RootFileNameAndEnsureTargetFolderExists(string fileName), enclose the call Directory.CreateDirectory(directory); in a try catch statement then swallow the exception and log it, in that way it may avoid the throwing of exception.  

My idea may look like this:

try

{

    Directory.CreateDirectory(directory);

}

catch (DirectoryNotFoundException)

{

    FormattedEventLogTraceListener formattedEventLog =

        new FormattedEventLogTraceListener("Enterprise Library",

            "Application", null);

    formattedEventLog.Write("Failed Creating Rolling Flat File.");

}

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com