|
@@ -87,8 +87,7 @@ namespace Vit.Core.Module.Log
|
|
return fileCache.GetPath(level);
|
|
return fileCache.GetPath(level);
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
public void LogTxt(Level level, string message)
|
|
public void LogTxt(Level level, string message)
|
|
@@ -96,9 +95,10 @@ namespace Vit.Core.Module.Log
|
|
//加锁 以避免多线程抢占文件错误
|
|
//加锁 以避免多线程抢占文件错误
|
|
// IOException: The process cannot access the file 'file path' because it is being used by another process
|
|
// IOException: The process cannot access the file 'file path' because it is being used by another process
|
|
|
|
|
|
|
|
+ string finalMsg = DateTime.Now.ToString("[HH:mm:ss.ffff]") + message + Environment.NewLine;
|
|
string filePath = GetLogPath(level);
|
|
string filePath = GetLogPath(level);
|
|
lock (filePath)
|
|
lock (filePath)
|
|
- File.AppendAllText(filePath, message);
|
|
|
|
|
|
+ File.AppendAllText(filePath, finalMsg);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -106,14 +106,16 @@ namespace Vit.Core.Module.Log
|
|
|
|
|
|
|
|
|
|
#region Log
|
|
#region Log
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 例如 (level, msg)=> { Console.WriteLine("[" + level + "]" + DateTime.Now.ToString("[HH:mm:ss.ffff]") + msg); };
|
|
|
|
+ /// </summary>
|
|
public Action<Level, string> OnLog = null;
|
|
public Action<Level, string> OnLog = null;
|
|
public void Log(Level level, string message)
|
|
public void Log(Level level, string message)
|
|
{
|
|
{
|
|
try
|
|
try
|
|
- {
|
|
|
|
- string finalMsg = DateTime.Now.ToString("[HH:mm:ss.ffff]") + message+ Environment.NewLine;
|
|
|
|
- LogTxt(level, finalMsg);
|
|
|
|
- OnLog?.Invoke(level, finalMsg);
|
|
|
|
|
|
+ {
|
|
|
|
+ LogTxt(level, message);
|
|
|
|
+ OnLog?.Invoke(level, message);
|
|
}
|
|
}
|
|
catch { }
|
|
catch { }
|
|
}
|
|
}
|