I decided to use log4net as a logger for a new webservice project. Everything is working fine, but I get a lot of messages like the one below, for every log4net tag I am usi
Just a word of warning to anyone follow the advice of the answers in this thread. There is a possible security risk by having the log4net configuration in an xml off the root of the web service, as it will be accessible to anyone by default. Just be advised if your configuration contains sensitive data, you may want to put it else where.
Have you tried using a separate log4net.config file?
I followed Kit's answer https://stackoverflow.com/a/11780781/6139051 and it didn't worked for AppenderType values like "log4net.Appender.TraceAppender, log4net". The log4net.dll assembly has the AssemblyTitle of "log4net", i.e. the assembly name does not have a dot inside, that was why the regex in Kit's answer didn't work. I has to add the question mark after the third parenthetical group in the regexp, and after that it worked flawlessly.
The modified regex looks like the following:
<xs:pattern value="[A-Za-z_]\w*(\.[A-Za-z_]\w*)+(\s*,\s*[A-Za-z_]\w*(\.[A-Za-z_]\w*)?+)?"/>
Actually you don't need to stick to the .xml extension. You can specify any other extension in the ConfigFileExtension attribute:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", ConfigFileExtension=".config", Watch = true)]
@steve_mtl: Changing the file extensions from .config
to .xml
solved the problem. Thank you.
@Wheelie: I couldn't try your suggestion, because I needed a solution which works with an unmodified Visual Studio installation.
To sum it up, here is how to solve the problem:
xml
-file. Make sure to use .xml
as file extension.Add the following line to AssemblyInfo.cs
:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "xmlFile.xml", Watch = true)]
Without modifying your Visual Studio installation, and to take into account proper versioning/etc. amongst the rest of your team, add the .xsd file to your solution (as a 'Solution Item'), or if you only want it for a particular project, just embed it there.