测井工具和log4net进行测井

测井工具和log4net进行测井

本文介绍了使用Castle Windsor,测井工具和log4net进行测井的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是:

log4net.config

log4net.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <log4net>
    <appender name="MyLog" type="log4net.Appender.RollingFileAppender">
      <file value="logs\log-file.txt" />
      <appendToFile value="true" />
      <maximumFileSize value="100KB" />
      <maxSizeRollBackups value="2" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%level %thread %logger - %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="MyWayLog" />
    </root>
  </log4net>
</configuration>

LoggerInstaler.cs

LoggerInstaler.cs

public class LoggerInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.AddFacility<LoggingFacility>(f => f.UseLog4Net().WithConfig("log4net.config"));
    }
}

MyLogger.cs

MyLogger.cs

private static ILoggerFactory loggera = IoC.Container.Resolve<ILoggerFactory>();

private static ILogger logger = loggera.Create("MyLog");

public static ILogger Log
{
    get { return logger; }
    set { logger = value; }
}

当我使用Log.Error("some exception")

在日志文件中,我还有其他一些dll的其他日志.我只想从调用(Log.Error)中显式获取我的日志,而不想要其他dll异常.

In log file I have other logs from some other dll. I want only my logs, not the other dll exception, only explicitly from call (Log.Error).

推荐答案

您必须使用

<logger name="MyLog">

代替

<root>

在log4net.config中

in the log4net.config

您还可以在Windsor内使用ToLog方法

You may also use ToLog method within windsor regitration

container.AddFacility<LoggingFacility>(f => f.UseLog4Net().WithConfig("log4net.config").ToLog("MyLog"));

不确定您的MyLogger.cs:由于使用了windsor功能,因此不需要...只需在需要时将ILogger设置为依赖项

Not sure about your MyLogger.cs: Due to windsor facility, there's should no need for that...simply set ILogger as dependency when you need it

这篇关于使用Castle Windsor,测井工具和log4net进行测井的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:22