public static LogObj MakeLogObj(string objName, object obj) { LogObj result = new LogObj(); result.ObjName = objName; result.Obj = obj; return(result); }
private void WriteLog(Exception ex, LogLevel level, string message, params object[] args) { LogEventInfo ei = new LogEventInfo(); ei.Properties[WorkflowApp_Const] = WorkflowApp; ei.Properties[BusinessID_Const] = string.Empty; ei.Properties[MethodName_Const] = string.Empty; ei.Properties[BizAppCode_Const] = string.Empty; ei.Level = level; //生成message内容 Dictionary <string, object> dict = new Dictionary <string, object>(); if (!string.IsNullOrEmpty(message)) { dict.Add("Message", message); } foreach (object obj in args) { if (obj != null) { if (obj is LogObj) { LogObj o = (LogObj)obj; dict.Add(o.ObjName, o.Obj); } else { dict.Add(obj.GetType().Name, obj); } } } if (!dict.ContainsKey("ClientIP")) { dict.Add("ClientIP", GetClientIPAddress()); } if (!dict.ContainsKey("BrowserInfo")) { dict.Add("BrowserInfo", GetBrowserType()); } if ((string.IsNullOrEmpty(message) && dict.Count > 0) || (!string.IsNullOrEmpty(message) && dict.Count > 1)) { object outStr = null;; if (dict.TryGetValue(BusinessID_Const, out outStr) && outStr is string) { ei.Properties[BusinessID_Const] = (string)outStr; } outStr = null; if (dict.TryGetValue(MethodName_Const, out outStr) && outStr is string) { ei.Properties[MethodName_Const] = (string)outStr; } outStr = null; if (dict.TryGetValue(BizAppCode_Const, out outStr) && outStr is string) { ei.Properties[BizAppCode_Const] = (string)outStr; } ei.Message = JsonConvert.SerializeObject(dict); } else { ei.Message = message; } ei.Exception = ex; logger.Log(ei); }