简体   繁体   English

log4net-事件查看器追加程序不起作用

[英]log4net - event viewer appender not working

I checked: 我检查了:

log4net with EventLogAppender doesn't log 带有EventLogAppender的log4net不会记录

and tried to do almost the same as the answer in that question, but without success, and also I'm running Visual Studio as an admin. 并试图做与该问题的答案几乎相同的方法,但是没有成功,而且我以管理员身份运行Visual Studio。

.config file looks like this: .config文件如下所示:

  <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>

    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
  </startup>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <appSettings>
    <add key="log4net.Internal.Debug" value="true" />
  </appSettings>
  <log4net>
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
      <layout type="log4net.Layout.Patternlayout">
        <conversionPattern value="%date %-5level %logger - %message%newline "/>
      </layout>
      <!--<level value="ALL"/>-->
      <threshhold value="ALL"></threshhold>
      <!--<param name="Threshold" value="ERROR" />-->
      <!--<logName value="Services"/>-->
      <applicationName value="SikuliTestResultImporter"/>
    </appender>
    <root>
      <level value="ALL"/>
      <appender-ref ref="EventLogAppender"/>
    </root>
  </log4net>
</configuration>

And I try to do something like this: 我尝试做这样的事情:

private static readonly ILog log = LogManager.GetLogger("EventLogAppender");

try
{
    throw new Exception("Exception mon!");
}
catch (Exception ex)
{
    log.Error(ex.Message);
}

I'm using log4net assembly for .NET 2, if that has to do with anything. 我正在为.NET 2使用log4net程序集,如果这与任何事情有关。

I just get the error that the .config is not a valid xml file: 我只是得到一个错误,即.config不是有效的xml文件:

log4net:ERROR Exception while reading ConfigurationSettings. log4net:ERROR读取ConfigurationSettings时发生异常。 Check your .config file is well formed XML. 检查您的.config文件格式是否正确。

Try this: (the configSections goes first, unless you got the exception you described) 尝试以下操作:(除非您遇到了描述的异常,否则configSections首先出现)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <startup>
       <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
  </startup>
  <appSettings>
    <add key="log4net.Internal.Debug" value="true" />
  </appSettings>
  <log4net>
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
      <layout type="log4net.Layout.Patternlayout">
        <conversionPattern value="%date %-5level %logger - %message%newline "/>
      </layout>
      <!--<level value="ALL"/>-->
      <threshhold value="ALL"></threshhold>
      <!--<param name="Threshold" value="ERROR" />-->
      <!--<logName value="Services"/>-->
      <applicationName value="SikuliTestResultImporter"/>
    </appender>
    <root>
      <level value="ALL"/>
      <appender-ref ref="EventLogAppender"/>
    </root>
  </log4net>
</configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM