很多人在asp.net开发使用log4net开发的时候总是有这个未“能找到元素“log4net”的架构信息”
英文为:Could not find schema information for the element 'log4net'
这是因为使用了默认配置,调用web.config
void Application_Start(object sender, EventArgs e) { // Code that runs on application startup log4net.Config.XmlConfigurator.Configure(); }
解决方法:
1.在应用程序中新建一个文件log4net.xml.
2.
void Application_Start(object sender, EventArgs e) { // Code that runs on application startup log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath("log4net.xml"))); }
这样就没有这个提示了。
3.本人也找了很久。看到很多网友问。故此贴出来。
4.下面log4net.xml代码
<?xml version="1.0"?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" /> </configSections> <log4net> <appender name="FileAppender" type="log4net.Appender.FileAppender"> <param name="File" value="c:\\log.log"/> <param name="AppendToFile" value="true"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" /> </layout> </appender> <root> <level value="ALL" /> <appender-ref ref="FileAppender"/> </root> </log4net> </configuration>