Log4Net Config setup error : No appender named [FileAppender] could be found
Log4Net Config setup error : No appender named [FileAppender] could be found
我已经使用 .Net Core 6.0 创建了一个 lognet 库。
库 class 具有以下初始化。
public static class MyLogger
{
private static readonly ILog logger = LogManager.GetLogger("");
static MyLogger()
{
log4net.Config.XmlConfigurator.Configure();
}
}
在我的控制台应用程序的 app.config 中有以下设置,
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\Logs\Test.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="Info" />
<level value="Warn" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
</configuration>
我的研究并没有帮助我解决问题。感谢您的帮助。
更改您的根配置以使用现有的附加程序:
<appender-ref ref="RollingFileAppender" />
我已经使用 .Net Core 6.0 创建了一个 lognet 库。
库 class 具有以下初始化。
public static class MyLogger
{
private static readonly ILog logger = LogManager.GetLogger("");
static MyLogger()
{
log4net.Config.XmlConfigurator.Configure();
}
}
在我的控制台应用程序的 app.config 中有以下设置,
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\Logs\Test.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="Info" />
<level value="Warn" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
</configuration>
我的研究并没有帮助我解决问题。感谢您的帮助。
更改您的根配置以使用现有的附加程序:
<appender-ref ref="RollingFileAppender" />