/// <summary>
/// 使用文本记录异常日志
/// </summary>
/// <Author>Ryanding</Author>
/// <date>2011-05-01</date>
public static void LoadFileAppender()
{
string currentPath = AppDomain.CurrentDomain.BaseDirectory;
string txtLogPath = string.Empty;
string iisBinPath = AppDomain.CurrentDomain.RelativeSearchPath;
if (!string.IsNullOrEmpty(iisBinPath))
txtLogPath = Path.Combine(iisBinPath, string.Format("log/ErrorLog{0}.txt", DateTime.Now.ToString("yyyy-MM-dd")));
else
txtLogPath = Path.Combine(currentPath, string.Format("log/ErrorLog{0}.txt", DateTime.Now.ToString("yyyy-MM-dd")));
FileAppender fileAppender = new FileAppender();
fileAppender.Name = "LogFileAppender";
fileAppender.File = txtLogPath;
fileAppender.AppendToFile = true;
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "记录时间:%date 线程ID:[%thread] 日志级别:%-5level 出错类:%logger property:[%property{NDC}] - 错误描述:%message%newline";
patternLayout.ActivateOptions();
fileAppender.Layout = patternLayout;
//选择UTF8编码,确保中文不乱码。
fileAppender.Encoding = Encoding.UTF8;
fileAppender.ActivateOptions();
BasicConfigurator.Configure(fileAppender);
}
------解决思路----------------------
干嘛要用代码配置?本来就支持滑动日志的啊