1、自定义配置
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<datePattern value="yyyyMMdd\\yyyy-MM-dd'log.txt'" />
<encoding value="utf-8" />
<file value="..\\..\\logs\\" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<staticLogFileName value="false" />
<param name="MaxSizeRollBackups" value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline %nDatetime:%utcdate %nHostName:%property{log4net:HostName} %nThreadID:[%thread] %nLogLevel: %-5level %nClassName:%logger property: [%property{NDC}] - %nDescription:%message%newline %n" />
</layout>
</appender>
<root>
<level value="All" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
</configuration>
2、使用
public class MainWindowViewModel : BindableBase
{
private readonly ILog logger=LogManager.GetLogger(typeof(MainWindowViewModel));
public MainWindowViewModel()
{
logger.Debug("this is a Debug");
}
}
标签:Log4Net,MainWindowViewModel,使用,Debug,logger,public
From: https://www.cnblogs.com/guchen33/p/18026166