Enable logging without installing Enterprise library

Topics: Logging Application Block
Feb 1, 2010 at 2:02 PM
Edited Feb 1, 2010 at 2:21 PM



I have an application that uses E.L. for logging to a database table and to the event log. On my pc I have installed E.L., and the logging works fine (to event log and local DB).

But on the deployment server, no logging is added to the database or event log. Also, on another pc (without E.L. installed), logging doesn't work. On both the server and this other pc the following assemblies are present:

  • Microsoft.Practices.EnterpriseLibrary.Common.dll,
  • Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
  • Microsoft.Practices.EnterpriseLibrary.Logging.dll
  • Microsoft.Practices.ObjectBuilder2.dll
  • Microsoft.Practices.Unity.dll

I was wondering if there is a way to get the logging to work without having to install E.L., either by setting some registry settings, adding extra config, assemblies...?

Feb 1, 2010 at 3:21 PM

can you check if there is any exception thrown from the event log?

Feb 2, 2010 at 12:58 AM

I can think of a reason for why it would not log to the event viewer.  What value did you use for the Source and Log property of the Formatted EventLog Trace Listener? If you used the default values ("Enterprise Library Logging" as the source and "Application" for the Log property), the Enterprise Library Logging source should be first created in the Application log.  You can run the InstallServices.bat file that comes with enterprise library as it automaticaly creates that source and installs instrumentation stuff as well; or if you really don't want to install any entlib stuff , you can create it yourself thru this code:

EventLog.CreateEventSource("Enterprise Library Logging", "Application");

For logging to the database, have you run the script for the Logging database?  If yes, once you get the logging on the event viewer working, add the Formatted EventLog TraceListener under the Logging Errors and Warnings source so you can check for any details why logging to the database failed.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Feb 2, 2010 at 6:32 AM

Thanks for yours answers.

@ bfallar3: no, I get no exceptions

@ Sarah: The Log property is set to 'Application', the Source property is set to 'MyApp.Log'. So should I first create the MyApp.Log source on the server? (I'll give that a try anyway, thx)

About the database logging: I don't want to log to a separate database. I just have a Log table in my application database where I write my logging to.

The thing I'm struggling with is the fact that it all works fine on my local event log and database, but not on the server or on the other pc without Enterprise Library installed.


Feb 2, 2010 at 6:48 AM

Ok, as long as all the tables and stored procedures from the Logging database is in the database you want to use and you didn't change anything in the schema, that should work.

 I just remember, LAB will automatically create MyApp.Log for you.  The only time it won't work is if MyApp.Log is already registered in a different Log.  I forgot to ask, what's the os in your server?


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Feb 2, 2010 at 6:57 AM

I'm quite sure MyApp.Log isn't registered yet in a different log (is there a way to check that anyway?).

The server is Windows Server 2008 (Enterprise), with SQL Server 2008

Feb 2, 2010 at 7:06 AM

Ah, that might explain it.  You may not have permission to write to the event log.  Check your permission first.

On checking if the source is registered in a specific log, it's also in the EventLog class, I think it's EventLog.SourceExists or something like that. 


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.


Feb 2, 2010 at 9:37 AM

Indeed, the lack of permission was the problem. As you suggested earlier, I had to create the MyApp.Log source manually (in the registry). After doing that, logging to the event log worked fine!

Also, a little bit to my surprise, this also solved the database logging problem. Without making any changes there, the database logging also works fine now... Probably the configuration never got the the point of the database logging configuration because of the event log problem?

Anyway, thanks for your help!


Feb 2, 2010 at 9:39 AM

Yes, I remember that bug now, logging stops when logging to event log fails. 

Glad to be of help.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.