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);
}
}
用法
新聞熱點
疑難解答