c#日志记录帮助类分享_C#教程-查字典教程网
c#日志记录帮助类分享
c#日志记录帮助类分享
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:publicclassLogHelper{privatestaticvoidInfo(stringcategory,int...

复制代码 代码如下:

public class LogHelper

{

private static void Info(string category, int priority, TraceEventType severity, string message)

{

IDictionary<string, object> dic = new Dictionary<string, object>();

dic.Add("属性:", category);

dic.Add("内容:", message);

ICollection<string> coll = new List<string>();

coll.Add("General");

LogEntry log = new LogEntry();

log.Priority = priority;

log.Severity = severity;

log.Message = category;//"日志测试";

log.TimeStamp = DateTime.Now;

log.ExtendedProperties = dic;//记录额外的信息

log.Categories = coll;//设置记录的日志类型

Logger.Write(log);

}

public static void Debug(string message)

{

Info("Debug", 1, TraceEventType.Information, message);

}

public static void DebugFormat(string format, params object[] args)

{

Info("Debug", 1, TraceEventType.Information, String.Format(format, args));

}

public static void Trace(string message)

{

Info("Trace", 1, TraceEventType.Information, message);

}

public static void TraceFormat(string format, params object[] args)

{

Info("Trace", 1, TraceEventType.Information, String.Format(format, args));

}

public static void Error(string message)

{

Info("Error", 1, TraceEventType.Error, message);

}

public static void ErrorFormat(string format, params object[] args)

{

Info("Error", 1, TraceEventType.Error, String.Format(format, args));

}

public static void Error(object obj, Exception ex)

{

Info("Error", 1, TraceEventType.Error, String.Format("Error Info:{0},{1}", obj, ex.Message));

}

//日志记录

public static void WriteLog(string errorTitle, string properties, string content)

{

IDictionary<string, object> dic = new Dictionary<string, object>();

dic.Add("属性:", properties);

dic.Add("内容:", content);

ICollection<string> coll = new List<string>();

coll.Add("General");

LogEntry log = new LogEntry();

log.Message = errorTitle;//"日志测试";

log.TimeStamp = DateTime.Now;

log.ExtendedProperties = dic;//记录额外的信息

log.Categories = coll;//设置记录的日志类型

Logger.Write(log);

}

}

用法

复制代码 代码如下:

#region 根据JobNO获取对应操作人员姓名 EMPLOYEE 表

/// <summary>

/// 根据JobNO获取对应操作人员姓名

/// </summary>

/// <param name="jobNo">JobNO</param>

/// <returns></returns>

public static string GetManagerNameByjobNo(string jobNo)

{

string strSql = "select IN_USER from IMPGTBILL where JOB_NO=@jobNo";

try

{

object temp = SqlHelper.Instance("Conn_GM")

.ExecuteScalar(strSql, new[] { new SqlParameter("@jobNo", jobNo) });

if (temp != null)

{

return temp.ToString();

}

return "";

}

catch (Exception e)

{

LogHelper.ErrorFormat("OrderTitle_DAL.GetManagerNameByjobNo:{0}", e.Message);

return null;

}

}

#endregion

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新C#教程学习
    热门C#教程学习
    编程开发子分类