2

我有以下app.config:

 <log4net>
  <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <param name="File" value="S3Logger.log"/>
    <appendToFile value="true" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="10MB" />
    <staticLogFileName value="true" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %level %logger - %message%newline" />
    </layout>
  </appender>
  <appender name="RemotingAppender" type="log4net.Appender.RemotingAppender" >
    <sink value="tcp://localhost:7070/LoggingSink" />
    <lossy value="false" />
    <bufferSize value="1" />
  </appender>

  <!-- Setup the root category, add the appenders and set the default level -->
  <root>
    <appender-ref ref="RollingFileAppender" />
    <appender-ref ref="RemotingAppender" />
  </root>
</log4net>

以及后面的代码:

   public partial class App : Application
{
    NameValueCollection appConfig = ConfigurationManager.AppSettings;
    private readonly ILog log = LogManager.GetLogger(typeof(App));
    private TaskbarIcon tb;

    public App()
    {
        InitializeComponent();
        XmlConfigurator.Configure();
        //initialize NotifyIcon
        if (getServiceStatus() == ServiceControllerStatus.Running)
        {
            tb = (TaskbarIcon)FindResource("ActiveServiceIcon");
        }
        else
        {
            tb = (TaskbarIcon)FindResource("InactiveServiceIcon");
        }
        log.Debug("Icon Created");

    }

}

出于某种原因,我只在文件中获取日志记录,而不是通过 log2console “.net remoting reciever” 知道为什么吗?

(我正在使用通过 nuget 安装的 vs2012 和 log4net)

4

1 回答 1

1

log4net 远程附加程序的相同问题,所有设置都是正确的,但 Log2Console 只是保持沉默。试试 UDP appender,它对我来说很好用。

配置:

<appender name="UdpAppender" type="log4net.Appender.UdpAppender">
   <remoteAddress value="127.0.0.1" />
   <remotePort value="7071" />
   <layout type="log4net.Layout.XmlLayoutSchemaLog4j" />
</appender>

Log2Console 接收器:

Log2Console 接收器

于 2016-08-25T12:53:11.950 回答