Log4Net Messages "Could not find schema information"

I decided to use log4net as a registrar for a new webservice project. Everything works fine, but I get a lot of messages like the following for every log4net tag that I use in my web.config :

Could not find schema information for element 'log4net' ...

Below are the relevant parts of my web.config :

  <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net> <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"> <file value="C:\log.txt" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="100KB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level: %message%newline" /> </layout> </appender> <logger name="TIMServerLog"> <level value="DEBUG" /> <appender-ref ref="RollingFileAppender" /> </logger> </log4net> 

It is decided:

  • Copy each log4net tag to a separate xml file. Be sure to use .xml as the file extension.
  • Add the following line to AssemblyInfo.cs :
 [assembly: log4net.Config.XmlConfigurator(ConfigFile = "xmlFile.xml", Watch = true)] 

nemo added:

Just a warning word, follow the recommendations of the responses to this thread. There is a security risk using the log4net configuration in xml from the root of the web service, as this will be accessible to everyone by default. Just if your configuration contains sensitive data, you might want to put it another way.




@wcm: I tried using a separate file. I added the following line to AssemblyInfo.cs

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

and put everything related to log4net in this file, but I still get the same messages.

+53
logging web-services web-config schema log4net
Oct 06 '08 at 14:11
source share
13 answers

I had a different approach and I need the following syntax:

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

which is different from the last xsl post but made a difference for me. Check out this blog post , it helped me.

+17
Oct 06 '08 at 20:43
source share

You can bind in the diagram to the log4net element. There are several floating around; most of them do not fully provide the various options available. I created the following xsd to provide as much verification as possible: http://csharptest.net/downloads/schema/log4net.xsd

You can easily bind it to xml by changing the log4net element:

 <log4net xsi:noNamespaceSchemaLocation="http://csharptest.net/downloads/schema/log4net.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
+67
Nov 08 '08 at 20:59
source share

Just a word of warning to someone follows the tips of the answers in this thread. There is a possible security risk since the log4net configuration in xml is outside the root of the web service, as it will be accessible to any user by default. Just keep in mind that if your configuration contains sensitive data, you might want to add it somewhere else.

+8
Nov 24 '08 at 20:07
source share

I believe that you see the message because Visual Studio does not know how to check the log4net section in the configuration file. You can fix this by copying log4net XSD to C: \ Program Files \ Microsoft Visual Studio 8 \ XML \ Schemas (or where your Visual Studio is installed). As an added bonus, you should now get intellisense support for log4net

+5
Oct. 06 '08 at 14:33
source share

In fact, you do not need to stick with the .xml extension. You can specify any other extension in the ConfigFileExtension attribute:

 [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", ConfigFileExtension=".config", Watch = true)] 
+3
Jul 24 '09 at 9:16
source share

@steve_mtl: changing the file extensions from .config to .xml solved the problem. Thank.

@Wheelie: I could not try your suggestion because I need a solution that works with an unmodified installation of Visual Studio.




To summarize, here's how to solve the problem:

  • Copy each log4net tag into a separate xml file. Be sure to use .xml as the file extension.
  • Add the following line to AssemblyInfo.cs :

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

+2
Oct 07 '08 at 7:37
source share

For VS2008, just add the log4net.xsd file to your project; VS looks into the project folder, as well as the installation directory mentioned by Wheelie.

In addition, using the .config extension instead of the .xml prevents a security issue because IIS does not support * .config files by default.

+2
Dec 12 '08 at 7:39
source share

In Roger's Response , where he provided the outline, this worked very well for me, except when the commentator mentioned

This XSD complains about using custom applications. It only allows the application from the default set (defined as an enumeration) instead of just creating this row field

I changed the original schema with xs:simpletype named log4netAppenderTypes and deleted the enumerations. Instead, I limited it to a basic .NET typing pattern (I say basic because it only supports file_name or typename, assembly ), however someone can extend it.

Just replace the definition of log4netAppenderTypes following in XSD:

 <xs:simpleType name="log4netAppenderTypes"> <xs:restriction base="xs:string"> <xs:pattern value="[A-Za-z_]\w*(\.[A-Za-z_]\w*)+(\s*,\s*[A-Za-z_]\w*(\.[A-Za-z_]\w*)+)?"/> </xs:restriction> </xs:simpleType> 

I pass this on to the original author if he wants to include it in his official version. Until then, you will have to download and modify xsd and link to it accordingly, for example:

 <log4net xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Dependencies/log4net/log4net.xsd"> <!-- ... --> </log4net> 
+2
Aug 02 2018-12-12T00:
source share

Have you tried using a separate log4net.config file?

+1
06 Oct '08 at 14:21
source share

I got an asp test project for assembly by putting the xsd file in the visual studio schemas folder as described above (for me it is C: \ Program Files \ Microsoft Visual Studio 8 \ XML \ Schemas) and then making my web.config look like this :

 <?xml version="1.0"?> <!-- Note: As an alternative to hand editing this file you can use the web admin tool to configure settings for your application. Use the Website->Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in \Windows\Microsoft.Net\Framework\v2.x\Config --> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> </configSections> <appSettings> </appSettings> <connectionStrings> </connectionStrings> <system.web> <trace enabled="true" pageOutput="true" /> <!-- Set compilation debug="true" to insert debugging symbols into the compiled page. Because this affects performance, set this value to true only during development. --> <compilation debug="true" /> <!-- The <authentication> section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. --> <authentication mode="Windows" /> <customErrors mode="Off"/> <!-- <customErrors mode="Off"/> The <customErrors> section enables configuration of what to do if/when an unhandled error occurs during the execution of a request. Specifically, it enables developers to configure html error pages to be displayed in place of a error stack trace. <customErrors mode="On" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> --> </system.web> <log4net xsi:noNamespaceSchemaLocation="http://csharptest.net/downloads/schema/log4net.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <appender name="LogFileAppender" type="log4net.Appender.FileAppender"> <!-- Please make shure the ..\\Logs directory exists! --> <param name="File" value="Logs\\Log4Net.log"/> <!--<param name="AppendToFile" value="true"/>--> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p %c %m%n"/> </layout> </appender> <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender"> <to value="" /> <from value="" /> <subject value="" /> <smtpHost value="" /> <bufferSize value="512" /> <lossy value="true" /> <evaluator type="log4net.Core.LevelEvaluator"> <threshold value="WARN"/> </evaluator> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%newline%date [%thread] %-5level %logger [%property] - %message%newline%newline%newline" /> </layout> </appender> <logger name="File"> <level value="ALL" /> <appender-ref ref="LogFileAppender" /> </logger> <logger name="EmailLog"> <level value="ALL" /> <appender-ref ref="SmtpAppender" /> </logger> </log4net> </configuration> 
+1
Jul 31 '09 at 11:22
source share

Without changing the installation of Visual Studio and considering the proper version control of / etc. among the rest of your team, add the .xsd file to your solution (as a โ€œsolution elementโ€), or if you only want it for a specific project, just paste it there.

0
Mar 07 '11 at 23:16
source share

I slowed it down a bit, but if you look at the examples you will find in the log4net logs, you can put all the configuration data in app.config, with one difference, the registration configsection:

 <!-- Register a section handler for the log4net section --> <configSections> <section name="log4net" type="System.Configuration.IgnoreSectionHandler" /> </configSections> 

Could a type definition of "System.Configuration.IgnoreSectionHandler" cause Visual Studio to not display any error / error messages in log4net materials?

0
Feb 15 '15 at 17:07
source share

I followed Kit answer answer https://stackoverflow.com/a/4129441/ and it did not work for AppenderType values โ€‹โ€‹like msgstr "log4net.Appender.TraceAppender, log4net". The assembly log4net.dll has an AssemblyTitle from "log4net", that is, the assembly name does not have a dot inside, so the regex in the "Set" response does not work. I have to add a question mark after the third bracket group in regexp, and after that it worked flawlessly.

The modified regex is as follows:

 <xs:pattern value="[A-Za-z_]\w*(\.[A-Za-z_]\w*)+(\s*,\s*[A-Za-z_]\w*(\.[A-Za-z_]\w*)?+)?"/> 
0
Mar 02 '17 at 18:09
source share