private static string WriteLog(LogEntry log, List<ILogEmitter> logEmitterList) { if (logEmitterList == null || logEmitterList.Count <= 0) { return log.LogID; } try { log.CheckData(); foreach (var logEmitter in logEmitterList) { if (logEmitter == null) { continue; } try { logEmitter.EmitLog(log); } catch (Exception ex) { string message = string.Format("Write log failed.\r\n\r\n Error Info: {0}. \r\n\r\n Log Type: {1}. \r\n\r\n Log Info: {2}", ex.ToString(), logEmitter.GetType().AssemblyQualifiedName, new XmlSerializer().Serialization(log,log.GetType())); Logger.WriteEventLog("ECCentral.Service.Utility_LoggingComponent", message, EventLogEntryType.Error); } } } catch (Exception ex) { string message = string.Format("Write log failed.\r\n\r\n Error Info: {0}. \r\n\r\n Log Info: {1}", ex.ToString(), new XmlSerializer().Serialization(log,log.GetType())); Logger.WriteEventLog("ECCentral.Service.Utility_LoggingComponent", message, EventLogEntryType.Error); } return log.LogID; }
public static string WriteLog(string content, string category, string referenceKey, List<ExtendedPropertyData> extendedProperties) { LogEntry log = new LogEntry(); log.Category = category; log.Content = content; log.ReferenceKey = referenceKey; log.ExtendedProperties = extendedProperties; return WriteLog(log); }
public void EmitLog(LogEntry log) { if (!Directory.Exists(m_LogFolderPath)) { Directory.CreateDirectory(m_LogFolderPath); } WriteToFile(new XmlSerializer().Serialization(log,log.GetType()), Path.Combine(m_LogFolderPath, DateTime.Now.ToString("yyyy-MM-dd") + ".txt")); }
public static string HandleException(Exception ex, string category, List<ExtendedPropertyData> extendedProperties, string referenceKey) { if (string.IsNullOrEmpty(category)) { category = DEFAULT_CATEGORY; } LogEntry log = new LogEntry(); log.Category = category; log.ExtendedProperties = extendedProperties; log.Content = GetExceptionDetail(ex); //log.Content = LogUtility.BuildExceptionMessage(ex); log.ReferenceKey = referenceKey; return Logger.WriteLog(log); }
public static LogEntry GetLogEntry(Exception ex) { List<ExtendedPropertyData> list = new List<ExtendedPropertyData>(); if (DEFAULT_CATEGORY != null) { list.Add(new ExtendedPropertyData("Error Message", DEFAULT_CATEGORY)); } LogEntry log = new LogEntry(); log.Category = DEFAULT_CATEGORY; log.ExtendedProperties = list; log.Content = GetExceptionDetail(ex); log.ReferenceKey = null; return log; }
/// <summary> /// 记录错误日志 /// </summary> /// <param name="log"></param> public void Log(LogEntry log) { string m_LogFolderPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Log"); try { CustomDataCommand command = DataCommandManager.CreateCustomDataCommandFromConfig("CreateLogo"); command.SetParameterValue<LogEntry>(log); int result = command.ExecuteNonQuery(); } catch (Exception ex) { if (!Directory.Exists(m_LogFolderPath)) { Directory.CreateDirectory(m_LogFolderPath); } WriteToFile(new XmlSerializer().Serialization(log, log.GetType()), Path.Combine(m_LogFolderPath, DateTime.Now.ToString("yyyy-MM-dd") + ".txt")); } }
/// <summary> /// 记录错误日志 /// </summary> /// <param name="log"></param> public static void Log(LogEntry log) { RestClient.Post<LogEntry>("LogService/CreateLog", log); }
public void Log(LogEntry log) { ObjectFactory<ILogDataAccess>.Instance.Log(log); }
internal static string WriteLog(LogEntry log) { return WriteLog(log, EmitterFactory.Create()); }
/// <summary> /// 调用REST 服务记录日志到数据库 /// </summary> /// <param name="log"></param> public void EmitLog(LogEntry log) { RestClient.Post<LogEntry>(m_ServiceAddress, log); }