コード例 #1
0
ファイル: AutoTrace.cs プロジェクト: bluehands/Logging
        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);
            }
        }
コード例 #2
0
ファイル: AutoTrace.cs プロジェクト: bluehands/Logging
 public void Dispose()
 {
     if (m_LogMessageWriter == null)
     {
         return;
     }
     try
     {
         if (m_LogMessageWriter.IsTraceEnabled)
         {
             var end = s_StopWatch.Elapsed - m_StartTime;
             m_TraceStackHandle.Dispose();
             m_LogMessageWriter.WriteLogEntry(LogLevel.Trace, () => LogFormatters.TraceLeave(m_Message, end.TotalMilliseconds), m_Caller);
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex);
     }
 }