|
|
|
@ -43,26 +43,25 @@ public sealed class LoggingFileComponent : IServiceComponent
|
|
|
|
|
return string.Format(fileName, DateTime.UtcNow);
|
|
|
|
|
};
|
|
|
|
|
options.FileSizeLimitBytes = 5000 * 1024;
|
|
|
|
|
//options.MessageFormat = (logMsg) =>
|
|
|
|
|
//{
|
|
|
|
|
// var stringBuilder = new StringBuilder();
|
|
|
|
|
// stringBuilder.AppendLine("【日志级别】:" + logMsg.LogLevel);
|
|
|
|
|
// stringBuilder.AppendLine("【日志时间】:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
// stringBuilder.AppendLine("【日志内容】:" + logMsg.Message);
|
|
|
|
|
// if (logMsg.Exception != null)
|
|
|
|
|
// {
|
|
|
|
|
// stringBuilder.AppendLine("【异常信息】:" + logMsg.Exception);
|
|
|
|
|
// }
|
|
|
|
|
// stringBuilder.AppendLine("【ManagedThreadId】:" + System.Threading.Thread.CurrentThread.ManagedThreadId);
|
|
|
|
|
|
|
|
|
|
// if (logMsg.Context != null && logMsg.Context.Properties != null && logMsg.Context.Properties.Count > 0)
|
|
|
|
|
// {
|
|
|
|
|
// foreach (var prop in logMsg.Context.Properties)
|
|
|
|
|
// {
|
|
|
|
|
// stringBuilder.AppendLine($"【属性】{prop.Key}:{prop.Value}");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// return stringBuilder.ToString();
|
|
|
|
|
//};
|
|
|
|
|
options.MessageFormat = (logMsg) =>
|
|
|
|
|
{
|
|
|
|
|
var stringBuilder = new StringBuilder();
|
|
|
|
|
stringBuilder.AppendLine($"[{logMsg.LogLevel}] [{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")}] [{logMsg.LogName}] [{System.Threading.Thread.CurrentThread.ManagedThreadId}] ");
|
|
|
|
|
stringBuilder.AppendLine($" {logMsg.Message}");
|
|
|
|
|
if (logMsg.Exception != null)
|
|
|
|
|
{
|
|
|
|
|
stringBuilder.AppendLine(logMsg.Exception.Message);
|
|
|
|
|
stringBuilder.AppendLine(logMsg.Exception.StackTrace);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (logMsg.Context != null && logMsg.Context.Properties != null && logMsg.Context.Properties.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var prop in logMsg.Context.Properties)
|
|
|
|
|
{
|
|
|
|
|
stringBuilder.AppendLine($"{prop.Key}:{prop.Value}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return stringBuilder.ToString();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|