Log4Net “Could not find schema information” messages

后端 未结 13 799
故里飘歌
故里飘歌 2020-12-01 04:17

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

相关标签:
13条回答
  • 2020-12-01 04:43

    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.

    0 讨论(0)
  • 2020-12-01 04:43

    Have you tried using a separate log4net.config file?

    0 讨论(0)
  • 2020-12-01 04:43

    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*)?+)?"/>
    
    0 讨论(0)
  • 2020-12-01 04:44

    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)]
    
    0 讨论(0)
  • 2020-12-01 04:49

    @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:

    1. Copy every log4net specific tag to a separate xml-file. Make sure to use .xml as file extension.
    2. Add the following line to AssemblyInfo.cs:

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

    0 讨论(0)
  • 2020-12-01 04:58

    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.

    0 讨论(0)
提交回复
热议问题