Sportalcraft
Sportalcraft

Reputation: 265

log4net separate configuration file

I'm using log4net in my project. so far I used the App.config file as a configuration file, but now I want to put it in a different file.

here's what I did :

I moved <log4net> ... </log4net> to the new file

(<log4net> is right after <?xml version="1.0" encoding="utf-8" ?>)

on the App.config I changed the code as follow :

<configSections>
   <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>

<log4net configSource="log4net.config"/>

and changed this line (that I suspect that this is the line with the problem) :

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]

this line is not written to the Assemblyinfo.cs though. don't know if I should...

it is worth mentioning that this is working as long as the log4net.config file is inside the bin\debug folder, so that is why I suspect the line with the assembly making the problem, I want the file to be easily visible on the solution, alongside the App.config file and not in the bin folder. Also, it's work if I put there a string with the full path of the log4net.config, but this will make problem to use it on another computer, how can I make it work? thanks!

Upvotes: 0

Views: 76

Answers (1)

John Caprez
John Caprez

Reputation: 393

Make sure the property "Copy to output directory" for the log4net.config file is set to "Copy if newer". This way it is always copied to the bin/debug or bin/release folder when you run your project.

Upvotes: 1

Related Questions