private static void Write(TraceEventType severity, string fileName, string msg, Exception ex = null) { if (!IsEnabled) { return; } CheckInParam(); var dic = new Dictionary <string, object>(); var entry = new LogEntry(); LogCustomWriter.AddLogSource(fileName, _logformatType); dic.Add("ex", LogTemplate.GetException(ex)); dic.Add("msg", msg); dic.Add("severity", LogTemplate.GetSeverity(severity, _logformatType)); dic.Add("ManagedThreadId", GetThreadId()); LogCustomWriter.WriteLog(entry, fileName, dic); }
/// <summary> /// /// </summary> /// <param name="fileName"></param> /// <param name="logFormatType"></param> public void AddLogSource(string fileName, LogFormatType logFormatType) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName", "Log FileName is Null"); } if (!_traceSources.ContainsKey(fileName)) { lock (_safeObj) { if (!_traceSources.ContainsKey(fileName)) { var logRollingListener = new LogRollingFlatFileListener(Path.Combine(SavePath, fileName + ".Log"), LogTemplate.GetRollingFlatFileFormatter(logFormatType), RollSizeKB).CreateListener(_loggerType); var debugTraceListener = new DebugTraceListener(LogTemplate.GetDebugTraceFormatter(logFormatType)).CreateListener(_loggerType); var mainLogSource = new LogSource("MainLogSource", SourceLevels.All); mainLogSource.Listeners.Clear(); mainLogSource.Listeners.Add(logRollingListener); mainLogSource.Listeners.Add(debugTraceListener); _traceSources.Add(fileName, mainLogSource); } } } }