我有以下代码将日志项写入文件。它正确地创建了文件,但文件中没有任何内容(即它的大小始终为 0 字节)。我究竟做错了什么?
ILog log = LogManager.GetLogger("mainlog");
RollingFileAppender logAppender = new RollingFileAppender();
string filePath = ConfigurationManager.AppSettings["LoggingFilePath"];
filePath = filePath + "EventLog.csv";
logAppender.File = filePath;
logAppender.AppendToFile = true;
logAppender.RollingStyle = RollingFileAppender.RollingMode.Date;
logAppender.MaxSizeRollBackups = 60;
logAppender.StaticLogFileName = true;
log4net.Config.BasicConfigurator.Configure(logAppender);
logAppender.ActivateOptions();
StringBuilder sb = new StringBuilder();
sb.Append(DateTime.Now.ToShortDateString());
sb.Append(",");
sb.Append(DateTime.Now.ToShortTimeString());
sb.Append(",");
sb.Append(applicationID.ToString());
sb.Append(",");
sb.Append(itemName);
sb.Append(",");
sb.Append(itemException.Message);
sb.Append(",");
sb.Append(itemException.StackTrace);
sb.Append(",");
sb.Append(itemException.Source);
sb.Append(",");
sb.Append(itemException.TargetSite);
sb.Append(",");
sb.Append(itemEventType.ToString());
log.Debug(sb.ToString());
logAppender.Close();