public void WriteLogEntry(LogLevel logLevel, Func <string> messageFactory, string callerMethodName = null, Exception ex = null, params KeyValuePair <string, string>[] customProperties) { try { if (string.IsNullOrEmpty(callerMethodName)) { throw new ArgumentNullException(nameof(callerMethodName)); } if (messageFactory == null) { throw new ArgumentNullException(nameof(messageFactory)); } if (IsLogLevelEnabled(logLevel)) { var logEventInfo = new LogEventInfo { MessageFactory = messageFactory, Level = logLevel, ClassName = MessageCreatorFriendlyName, TypeName = MessageCreatorFullName, MethodName = callerMethodName, CallContext = TraceStack.CurrentStack(LogFormatters.ContextPartSeparator), Correlation = TrackCorrelation.Correlation, Indent = TraceStack.Indent.ConvertIndentToWhiteSpaces(), CustomProperties = customProperties }; WriteLogEntry(logEventInfo, ex); } } catch (Exception exx) { Debug.WriteLine(exx); } }
public AutoTrace(ILogMessageWriter logWriter, Func <string> messageFactory, [CallerMemberName] string caller = "", params KeyValuePair <string, string>[] customProperties) { try { if (logWriter == null) { return; } if (messageFactory == null) { return; } if (string.IsNullOrEmpty(caller)) { return; } m_Caller = caller; if (logWriter.IsTraceEnabled) { m_LogMessageWriter = logWriter; m_Message = GetMessage(messageFactory); m_StartTime = s_StopWatch.Elapsed; m_LogMessageWriter.WriteLogEntry(LogLevel.Trace, () => LogFormatters.TraceEnter(m_Message), m_Caller, customProperties: customProperties); m_TraceStackHandle = TraceStack.Push(LogFormatters.ContextPart(m_Caller)); } } catch (Exception ex) { Trace.WriteLine(ex); } }