避免在log4net中打印记录器名称

时间:2019-01-23 19:12:09

标签: c# uwp log4net xml-configuration

我正在UWP应用中使用log4net。

我的配置文件如下:

<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="false">
    <appender name="Console" type="log4net.Appender.DebugAppender">
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date - %message%newline" />
        </layout>
    </appender>

    <appender name="LocalStorageFile" type="MyProject.LocalStorageFileAppender, MyProject">
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date - %message%newline" />
        </layout>
    </appender>

    <root>
        <level value="INFO" />
        <appender-ref ref="Console" />
        <appender-ref ref="LocalStorageFile" />
    </root>
</log4net>

由于这是UWP应用程序,因此我需要使用以下方法手动加载XML文件:

private static async Task ConfigureLog4Net()
{
    // config for log4net:
    Uri uri = new Uri("ms-appx:///log4netConfig.xml");
    StorageFile sampleFile = await StorageFile.GetFileFromApplicationUriAsync(uri);
    var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
    using (Stream s = await sampleFile.OpenStreamForReadAsync())
    {
        log4net.Config.XmlConfigurator.Configure(logRepository, s);
    }
    Logger log = new Logger(typeof(AppConfigReader));
    log.InfoFormat("Log is configured");
}

但是,在我的日志中,总是有记录器的全限定名称,例如以下示例:

MyCorp.Controls.MyView:2019-01-23 10:38:32,434 - log test here

如何配置log4net以查看类似这样的日志(没有记录器名称):

2019-01-23 10:38:32,434 - log test here

0 个答案:

没有答案