Log4Net“无法找到架构信息";讯息 [英] Log4Net "Could not find schema information" messages

查看:288
本文介绍了Log4Net“无法找到架构信息";讯息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定将 log4net 用作新Web服务项目的记录器.一切正常,但是对于web.config中的每个log4net标记,我都会收到很多类似以下的消息:

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 using in my web.config:

找不到有关的架构信息 元素"log4net" ...

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

以下是我的web.config的相关部分:

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>

已解决:

  1. 将每个log4net特定的标签复制到单独的xml文件中.确保使用.xml作为文件扩展名.
  2. 将以下行添加到AssemblyInfo.cs:
  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)]

添加了

nemo :

向任何人发出警告 遵循答案的建议 这个线程.有可能 使用log4net会带来安全风险 在根目录下的xml中进行配置 Web服务,因为它将是 默认情况下任何人都可以访问.只是 如果您的配置被告知 包含您可能想要的敏感数据 放在其他地方.

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.


@wcm:我尝试使用单独的文件.我在AssemblyInfo.cs

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

并将处理log4net的所有内容都放入该文件中,但我仍然收到相同的消息.

and put everything dealing with log4net in that file, but I still get the same messages.

推荐答案

我有不同的看法,并且需要以下语法:

I had a different take, and needed the following syntax:

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

与xsl的上一篇文章有​​所不同,但对我来说却有所不同.查看此博客帖子,它帮助了我.

which differs from xsl's last post, but made a difference for me. Check out this blog post, it helped me out.

这篇关于Log4Net“无法找到架构信息";讯息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆