代码如下:
publicclassLogHelper
{
privatestaticvoidInfo(stringcategory,intpriority,TraceEventTypeseverity,stringmessage)
{
IDictionary<string,object>dic=newDictionary<string,object>();
dic.Add(“属性:”,category);
dic.Add(“内容:”,message);
ICollection<string>coll=newList<string>();
coll.Add(“General”);
LogEntrylog=newLogEntry();
log.Priority=priority;
log.Severity=severity;
log.Message=category;//”日志测试”;
log.TimeStamp=DateTime.Now;
log.ExtendedProperties=dic;//记录额外的信息
log.Categories=coll;//设置记录的日志类型
Logger.Write(log);
}
publicstaticvoidDebug(stringmessage)
{
Info(“Debug”,1,TraceEventType.Information,message);
}
publicstaticvoidDebugFormat(stringformat,paramsobject[]args)
{
Info(“Debug”,1,TraceEventType.Information,String.Format(format,args));
}
publicstaticvoidTrace(stringmessage)
{
Info(“Trace”,1,TraceEventType.Information,message);
}
publicstaticvoidTraceFormat(stringformat,paramsobject[]args)
{
Info(“Trace”,1,TraceEventType.Information,String.Format(format,args));
}
publicstaticvoidError(stringmessage)
{
Info(“Error”,1,TraceEventType.Error,message);
}
publicstaticvoidErrorFormat(stringformat,paramsobject[]args)
{
Info(“Error”,1,TraceEventType.Error,String.Format(format,args));
}
publicstaticvoidError(objectobj,Exceptionex)
{
Info(“Error”,1,TraceEventType.Error,String.Format(“ErrorInfo:{0},{1}”,obj,ex.Message));
}
//日志记录
publicstaticvoidWriteLog(stringerrorTitle,stringproperties,stringcontent)
{
IDictionary<string,object>dic=newDictionary<string,object>();
dic.Add(“属性:”,properties);
dic.Add(“内容:”,content);
ICollection<string>coll=newList<string>();
coll.Add(“General”);
LogEntrylog=newLogEntry();
log.Message=errorTitle;//”日志测试”;
log.TimeStamp=DateTime.Now;
log.ExtendedProperties=dic;//记录额外的信息
log.Categories=coll;//设置记录的日志类型
Logger.Write(log);
}
}
用法
代码如下:
#region根据JobNO获取对应操作人员姓名EMPLOYEE表
///<summary>
///根据JobNO获取对应操作人员姓名
///</summary>
///<paramname=”jobNo”>JobNO</param>
///<returns></returns>
publicstaticstringGetManagerNameByjobNo(stringjobNo)
{
stringstrSql=”selectIN_USERfromIMPGTBILLwhereJOB_NO=@jobNo”;
try
{
objecttemp=SqlHelper.Instance(“Conn_GM”)
.ExecuteScalar(strSql,new[]{newSqlParameter(“@jobNo”,jobNo)});
if(temp!=null)
{
returntemp.ToString();
}
return””;
}
catch(Exceptione)
{
LogHelper.ErrorFormat(“OrderTitle_DAL.GetManagerNameByjobNo:{0}”,e.Message);
returnnull;
}
}
#endregion
您可能感兴趣的文章:C#记录消息到日志文件的方法C#实现线程安全的简易日志记录方法c#程序定期把内存信息记录到log日志示例MVC使用Log4Net进行错误日志记录学习笔记4.netjMail邮件发送(含抄送、密送、多发、日志记录)实例代码ASP.NET记录错误日志的实现方法Log4net日志记录组件的使用步骤详解和下载记录PHP错误日志display_errors与log_errors的区别C#自定义日志记录
简要对比C语言中三个用于退出进程的函数
C语言中的setlinebuf()、utmpname()、rewind函数使用
上述就是C#学习教程:c#日志记录帮助类分享分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/905407.html