WebPart Logging with Microsoft Enterprise Library

In a previous post I explained how to do some validation with the Enterprise Library.

Now I am going to explain how you can do some logging in your WebPart. This can be handy if you want an overview of all your validation errors.

In my example I will just explain the default logging. This is the logging in the event-viewer.

This isn’t a hard thing to do. Just set a Reference to Microsoft.Practices.EnterpriseLibrary.Logging and you are good to go.

You also needs to add a Logging Block to your app.config file. This can easily been done with the Enterprise Library Configuration Tool.

To write something to the event-viewer you can do this with one line of code:


Of course before you can use the Logger you need to set:


Here a screenshot of my app (only the error messages) and the event-viewer:


Leave a Reply

Your email address will not be published. Required fields are marked *