c logging help class sharing
- 2020-06-15 10:09:05
- OfStack
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(" attribute :", category);
dic.Add(" content :", message);
ICollection<string> coll = new List<string>();
coll.Add("General");
LogEntry log = new LogEntry();
log.Priority = priority;
log.Severity = severity;
log.Message = category;//" Log test ";
log.TimeStamp = DateTime.Now;
log.ExtendedProperties = dic;// Record additional information
log.Categories = coll;// Sets the type of log to be logged
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));
}
// logging
public static void WriteLog(string errorTitle, string properties, string content)
{
IDictionary<string, object> dic = new Dictionary<string, object>();
dic.Add(" attribute :", properties);
dic.Add(" content :", content);
ICollection<string> coll = new List<string>();
coll.Add("General");
LogEntry log = new LogEntry();
log.Message = errorTitle;//" Log test ";
log.TimeStamp = DateTime.Now;
log.ExtendedProperties = dic;// Record additional information
log.Categories = coll;// Sets the type of log to be logged
Logger.Write(log);
}
}
usage
#region According to the JobNO Gets the name of the corresponding operator EMPLOYEE table
/// <summary>
/// According to the JobNO Gets the name of the corresponding operator
/// </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