c#日志記錄幫助類分享
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;//"日志測試";
log.TimeStamp = DateTime.Now;
log.ExtendedProperties = dic;//記錄額外的信息
log.Categories = coll;//設(shè)置記錄的日志類型
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;//"日志測試";
log.TimeStamp = DateTime.Now;
log.ExtendedProperties = dic;//記錄額外的信息
log.Categories = coll;//設(shè)置記錄的日志類型
Logger.Write(log);
}
}
用法
#region 根據(jù)JobNO獲取對應(yīng)操作人員姓名 EMPLOYEE 表
/// <summary>
/// 根據(jù)JobNO獲取對應(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#實現(xiàn)按照指定長度在數(shù)字前補(bǔ)0方法小結(jié)
這篇文章主要介紹了C#實現(xiàn)按照指定長度在數(shù)字前補(bǔ)0方法,實例總結(jié)了兩個常用的數(shù)字補(bǔ)0的技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04C#實現(xiàn)對文件進(jìn)行加密保護(hù)的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用C#實現(xiàn)對文件進(jìn)行加密保護(hù)的功能,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下2022-12-12WinFrom中l(wèi)abel背景透明的實現(xiàn)方法
這篇文章主要介紹了WinFrom中l(wèi)abel背景透明的實現(xiàn)方法,方法簡單實用,是C#程序設(shè)計中非常實用的技巧,需要的朋友可以參考下2014-09-09