c#日志記錄幫助類(lèi)分享
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("內(nèi)容:", message);
ICollection<string> coll = new List<string>();
coll.Add("General");
LogEntry log = new LogEntry();
log.Priority = priority;
log.Severity = severity;
log.Message = category;//"日志測(cè)試";
log.TimeStamp = DateTime.Now;
log.ExtendedProperties = dic;//記錄額外的信息
log.Categories = coll;//設(shè)置記錄的日志類(lèi)型
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("內(nèi)容:", content);
ICollection<string> coll = new List<string>();
coll.Add("General");
LogEntry log = new LogEntry();
log.Message = errorTitle;//"日志測(cè)試";
log.TimeStamp = DateTime.Now;
log.ExtendedProperties = dic;//記錄額外的信息
log.Categories = coll;//設(shè)置記錄的日志類(lèi)型
Logger.Write(log);
}
}
用法
#region 根據(jù)JobNO獲取對(duì)應(yīng)操作人員姓名 EMPLOYEE 表
/// <summary>
/// 根據(jù)JobNO獲取對(duì)應(yīng)操作人員姓名
/// </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
相關(guān)文章
C#實(shí)現(xiàn)按照指定長(zhǎng)度在數(shù)字前補(bǔ)0方法小結(jié)
這篇文章主要介紹了C#實(shí)現(xiàn)按照指定長(zhǎng)度在數(shù)字前補(bǔ)0方法,實(shí)例總結(jié)了兩個(gè)常用的數(shù)字補(bǔ)0的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04C#實(shí)現(xiàn)對(duì)文件進(jìn)行加密保護(hù)的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)對(duì)文件進(jìn)行加密保護(hù)的功能,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下2022-12-12WinFrom中l(wèi)abel背景透明的實(shí)現(xiàn)方法
這篇文章主要介紹了WinFrom中l(wèi)abel背景透明的實(shí)現(xiàn)方法,方法簡(jiǎn)單實(shí)用,是C#程序設(shè)計(jì)中非常實(shí)用的技巧,需要的朋友可以參考下2014-09-09C#多線程爬蟲(chóng)抓取免費(fèi)代理IP的示例代碼
本篇文章主要介紹了C#多線程爬蟲(chóng)抓取免費(fèi)代理IP的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-08-08C#開(kāi)源的AOP框架--KingAOP基礎(chǔ)
這篇文章主要介紹了一款C#開(kāi)源的AOP框架--KingAOP框架的基礎(chǔ)知識(shí),對(duì)于想學(xué)習(xí)AOP的小伙伴來(lái)說(shuō),非常不錯(cuò),希望大家能夠喜歡。2015-12-12