WPF中log4net的用法
WPF中如何使用log4net
http://www.cnblogs.com/C-Sharp2/archive/2013/04/12/WPF-LOG4NET.html
Apache log4net Manual: Configuration
http://logging.apache.org/log4net/release/manual/configuration.html
两点说明:
1.WPF中可以不在App.xaml.cs中做Configure()处理,只需要在要打log的文件中,在其开始的头部(如构造函数),写入如下配置程序即可。
public Server()
{
log4net.Config.XmlConfigurator.Configure(); // only config one time
InitializeComponent();
}
2.WPF的log4net.config和其他的web.xmlxxx配置不同,具体如下文件:
App1.config 配置文件:
<?xml version="1.0"?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/> </configSections> <log4net> <root> <level value="DEBUG"/> <!--<appender-ref ref="SmtpAppender"/>--> <appender-ref ref="LogFileAppender"/> <!--<appender-ref ref="ColoredConsoleAppender"/>--> </root> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="logs/cmm.log"/> <param name="AppendToFile" value="true"/> <rollingStyle value="Size"/> <maxSizeRollBackups value="10"/> <maximumFileSize value="1MB"/> <staticLogFileName value="true"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%02thread] %-5level %logger: %message%newline"/> </layout> </appender> <appender name="ColoredConsoleAppender" type="log4net.Appender.ConsoleAppender"> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger: %message%newline"/> </layout> </appender> <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender"> <to value="bobby.chopra@prcm.com"/> <from value="TagFileUploader@prcm.com"/> <subject value="TagFileUploader ERROR"/> <smtpHost value="prc-mn-ex01"/> <bufferSize value="512"/> <lossy value="true"/> <evaluator type="log4net.Core.LevelEvaluator"> <threshold value="ERROR"/> </evaluator> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger: %message%newline"/> </layout> </appender> </log4net> <!-- <startup> <supportedRuntime version="v3.5" sku=".NETFramework,Version=v3.5"/> </startup> --> </configuration>
还存在的问题:
1.要同时将debug, info, warn, fatal, all都显示在一个文件里,怎么弄?
2.远程服务器log如何配置上传?
3.格式化输出,结合窗口,实施显示log日志,貌似codeproject上有类似的程序写好的。
Other ref:
WPF中使用log4net
http://www.cnblogs.com/Feng-Scorpio/archive/2013/05/21/3091021.html
log4Net配置详解
http://www.cnblogs.com/Dot-Boy/archive/2008/07/07/1237806.html
Log4net用法
http://www.cnblogs.com/hfliyi/archive/2012/05/20/2510783.html