188 lines
5.0 KiB
C#
188 lines
5.0 KiB
C#
using Common.Logging;
|
|
using Lskj.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Lskj.Util
|
|
{
|
|
public static class LoggerHandler
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
public static void Debug(this object happenobj, object message)
|
|
{
|
|
if (log.IsDebugEnabled)
|
|
{
|
|
try
|
|
{
|
|
log.Debug(new LogInfo(happenobj) { msg = message });
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Error(message, e);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void Debug(this object happenobj, object message, Exception exception)
|
|
{
|
|
if (log.IsDebugEnabled)
|
|
try
|
|
{
|
|
log.Debug(new LogInfo(happenobj) { msg = message, exception = exception });
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Error(message, e);
|
|
}
|
|
}
|
|
|
|
public static void Error(this object happenobj, object message)
|
|
{
|
|
if (log.IsErrorEnabled)
|
|
try
|
|
{
|
|
log.Error(new LogInfo(happenobj) { msg = message });
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Error(message, e);
|
|
}
|
|
}
|
|
|
|
public static void Error(this object happenobj, object message, Exception exception)
|
|
{
|
|
if (log.IsErrorEnabled)
|
|
try
|
|
{
|
|
log.Error(new LogInfo(happenobj) { msg = message, exception = exception });
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
public static void Fatal(this object happenobj, object message)
|
|
{
|
|
if (log.IsFatalEnabled)
|
|
try
|
|
{
|
|
log.Fatal(new LogInfo(happenobj) { msg = message });
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Error(message, e);
|
|
}
|
|
}
|
|
|
|
public static void Fatal(this object happenobj, object message, Exception exception)
|
|
{
|
|
if (log.IsFatalEnabled)
|
|
try
|
|
{
|
|
log.Fatal(new LogInfo(happenobj) { msg = message, exception = exception });
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Error(message, e);
|
|
}
|
|
}
|
|
|
|
public static void Info(this object happenobj, object message)
|
|
{
|
|
if (log.IsInfoEnabled)
|
|
try
|
|
{
|
|
log.Info(new LogInfo(happenobj) { msg = message });
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Error(message, e);
|
|
}
|
|
}
|
|
|
|
public static void Info(this object happenobj, object message, Exception exception)
|
|
{
|
|
if (log.IsInfoEnabled)
|
|
try
|
|
{
|
|
log.Info(new LogInfo(happenobj) { msg = message, exception = exception });
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Error(message, e);
|
|
}
|
|
|
|
}
|
|
|
|
public static void Warn(this object happenobj, object message)
|
|
{
|
|
if (log.IsWarnEnabled)
|
|
try
|
|
{
|
|
log.Warn(new LogInfo(happenobj) { msg = message });
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Error(message, e);
|
|
}
|
|
}
|
|
|
|
public static void Warn(this object happenobj, object message, Exception exception)
|
|
{
|
|
if (log.IsWarnEnabled)
|
|
try
|
|
{
|
|
log.Warn(new LogInfo(happenobj) { msg = message, exception = exception });
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Error(message, e);
|
|
}
|
|
}
|
|
private static object lockObj = new object();
|
|
private static DateTime LastCheckDate = DateTime.Now;
|
|
}
|
|
public class LogInfo
|
|
{
|
|
public LogInfo(object happenobj)
|
|
: base()
|
|
{
|
|
this.happenobj = happenobj;
|
|
}
|
|
|
|
private object happenobj { get; set; }
|
|
|
|
/// <summary>
|
|
/// 信息
|
|
/// </summary>
|
|
public object msg { get; set; }
|
|
|
|
public string classname
|
|
{
|
|
get
|
|
{
|
|
return $"{happenobj.GetType().FullName}=>";
|
|
}
|
|
set { }
|
|
}
|
|
public string operatorId
|
|
{
|
|
get
|
|
{
|
|
return $"{ERPInfo.Instance.UserName}=>";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 异常
|
|
/// </summary>
|
|
public Exception exception { get; set; }
|
|
|
|
//more property;
|
|
public override string ToString()
|
|
{
|
|
|
|
return msg + "";
|
|
}
|
|
}
|
|
} |