前端之家收集整理的这篇文章主要介绍了
log4net使用记录,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
App.config里面配置:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="log\\mylog.log"></file>
<appendToFile value="true"></appendToFile>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%d]:%n%m%n"></conversionPattern>
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%d]:%n%m%n"></conversionPattern>
</layout>
</appender>
<root>
<level value="INFO"></level>
<appender-ref ref="FileAppender"></appender-ref>
<appender-ref ref="ConsoleAppender"></appender-ref>
</root>
<logger name="MyLogger">
<level value="ERROR"></level>
<appender-ref ref="FileAppender"></appender-ref>
<appender-ref ref="ConsoleAppender"></appender-ref>
</logger>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
AssemblyInfo.cs里面配置:
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "config",Watch = true)]
Program.cs里面
log4net.Config.XmlConfigurator.Configure();
原文链接:https://www.f2er.com/xml/298292.html