diff --git a/Log/Log.csproj b/Log/Log.csproj index 846fd05b9a67becaadcc240ae31bb8a633463c20..9c6d6433dc86547533a7c88f5993443f52ca5c46 100644 --- a/Log/Log.csproj +++ b/Log/Log.csproj @@ -69,6 +69,7 @@ + diff --git a/Log/Log.csproj.user b/Log/Log.csproj.user new file mode 100644 index 0000000000000000000000000000000000000000..c10e84bab3003321cc164654bf70a4d2df291927 --- /dev/null +++ b/Log/Log.csproj.user @@ -0,0 +1,6 @@ + + + + ProjectFiles + + \ No newline at end of file diff --git a/Log/SysLogger.cs b/Log/SysLogger.cs new file mode 100644 index 0000000000000000000000000000000000000000..043df61db0d2ed90710e06a7c2c1b397de2c9c55 --- /dev/null +++ b/Log/SysLogger.cs @@ -0,0 +1,113 @@ +//============================================================== +// °æȨËùÓУºÉîÛÚ½ÜÎĿƼ¼ +// ÎļþÃû£ºSystemLogger.cs +// °æ±¾£ºV1.0 +// ´´½¨ÕߣºJay ( QQ£º 85363208 ) +// ´´½¨Ê±¼ä£º2017-11-28 16:18 +// ´´½¨ÃèÊö£º +// ÐÞ¸ÄÕߣº +// ÐÞ¸Äʱ¼ä£º +// ÐÞ¸Ä˵Ã÷£º +//============================================================== + +using System; +using System.Configuration; +using System.Diagnostics; +using System.IO; +using System.ServiceModel; +using System.ServiceModel.Channels; + +namespace Infrastructure.Log +{ + public class SysLogger + { + //public static readonly SystemLogger Instance = new SystemLogger(); + + private static readonly Logger _Logger = null; + + public static string LogPath = ""; + + public static bool IsDebug = false; + + public static bool IsDaily = false; + + static SysLogger() + { + if (!Directory.Exists(LogPath)) + { + LogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log"); + if (!Directory.Exists(LogPath)) + { + Directory.CreateDirectory(LogPath); + } + } + + if (IsDaily) + { + _Logger = new DailyLogger(LogPath, "DailyLogger"); + } + else + { + _Logger = new HourlyLogger(LogPath, "HourlyLog"); + } + } + + public static void WriteAction(string id, string action) + { + RealWrite(id, action); + } + + public static void WriteSql(string id, string sql) + { + RealWrite(id, sql); + } + + public static void WriteError(Exception error) + { + WriteError("ERROR", error); + } + + public static void WriteError(string id, Exception error) + { + Exception ex = error.InnerException ?? error; + string content = string.Format("{0}£º{1}\r\n{2}", ex.GetType(), ex.Message, ex.StackTrace); + + RealWrite(id, content); + } + + public static void Write(string msg) + { + RealWrite("", msg); + } + + public static void Write(string id, string msg) + { + RealWrite(id, msg); + } + + private static void RealWrite(string id, string msg) + { + msg = string.Format("¡¾{0}({1})¡¿{2}", DateTime.Now.ToString("HH:mm:ss.fff"), id, msg); + + if (IsDebug) + { + Debug.WriteLine(msg); + } + else + { + Console.WriteLine(msg); + } + + _Logger.Write(msg); + } + + public void Close() + { + if (_Logger != null) + { + _Logger.Close(); + } + } + + } +}