Logging code doesn't work inside a class library

Topics: Logging Application Block
Oct 2, 2007 at 10:39 PM
Hey guys,

I implemented a class library which handles all the logging functionality.

A sample static method i have in the class library is shown below:

public class LogHandler
private LogHandler()


public static void LogEvent(object EventMsg, LogEventType EventType)
Logger.Write(EventMsg, EventType.ToString());

The problem is, I have a website application uses this class library, and I would like to call this static method to log some of the events, the method would just hang in there for a few seconds and then end excution without actually logging anything into the database.

instead if i just run the this line : Logger.Write(EventMsg, EventType.ToString()); in the website application, everything works fine.

Or if i run the above one line of code before excuting the static method, it runs ok too. So i am guessing this is related with the configuration or some sort of logger initialization procedure? Anyone please shed me some light?

Oct 3, 2007 at 12:08 PM

It shouldn't be related to configuration; regardless of where the Logger is being used the same app-wide configuration will be used. Are you using the signed binaries or are you building an unsigned version? What's the trust setting for your app?

Oct 3, 2007 at 1:05 PM
I am using the signed binaries, and i believe under the vs2005 embedded local hosting server, it should be full trust setting.
Oct 3, 2007 at 2:06 PM
Edited Oct 3, 2007 at 2:07 PM
After numerous testing, i found out while using the below method call

LogHandler.LogEvent(EventMsg, LogEventType.SMSSendEventLog);--> which eventually call this method Logger.Write(EventMsg, EventType.ToString());

if i pass in a string without any blank space as the first argument, everything runs smoothly, but if the first parameter contains any white spaces, the function call hangs in there for a few seconds and does not log anything into the database.

This is strange, is it possibly a bug or a known issue? anyone?
Oct 3, 2007 at 2:49 PM

I've figured it out. I've found out that my custom API class used for handling logging capabilities within the class library cannot be static or a regular class with a private constructor (thus static methods are called), it'll cause strange behaviors such as stalling for a few seconds without actually log in anything. I changed my static api class/methods into a regular class/methods, it works perfectly now.

but my question is why? does this has something to do with the parameter being passed into a static class? from my understanding, is it because the pamamether being passed into a static method got manipulated different in memory than a regular method? or this is a bug in enterprise library?
Oct 5, 2007 at 2:38 PM
Edited Oct 5, 2007 at 2:42 PM
Take a look at this article:
He has done a great job abstracting the Logger. It uses static methods with no issue.

An Extension to the Enterprise Library Logging Application Block