Tuesday, January 11, 2011

How to make Log4Net to work with a Windows Service assembly?

There are 2 main concerns with using Log4Net with Windows Service:

1. XmlConfigurator must have its Watch property set to true
2. The output log file must be written to a folder where the service user has writing rights

To solve this you can add this line to your AssemblyInfo.cs:

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

And you have to choose a suitable output path such as:

<file value="${ALLUSERSPROFILE}\Company\Product.log" />


Leslie Lim said...

I read your blog.I thought it was great.. Hope you have a great day. God bless.


gerald aburto said...

This saved my life, thanks for sharing

Anonymous said...

thanks helps me a lot.

dviorel said...

after a long search this post was helpful... thanks!!!