Пример #1
0
        public TraceContext(
            TraceContextConfiguration configuration,
            ContextName contextName,
            Guid correlationToken,
            TraceSource traceSource)
        {
            _configuration = configuration;
            _header        = string.Format("{0}#{1}", contextName.Value, correlationToken.ToString("D"));
            _traceBuffer   = new TraceBuffer((message, eventType, date) => traceSource.TraceEvent(eventType, 0,
                                                                                                  string.Format("{0} Trace ({1}):{2}", _header, date.ToString(CultureInfo.InvariantCulture), message)));
            _traceSource = traceSource;

            if (_configuration.BufferizeCatchExceptionAndFlash)
            {
                _trace = (m, e) => _traceBuffer.Trace(m, TraceEventType.Information);
            }
            else
            {
                _trace = (m, e) => traceSource.TraceEvent(e, 0, string.Format("{0} Trace {1}", _header, m));
            }
        }
Пример #2
0
 public TraceContext(string traceSourceName)
 {
     _traceSource   = new TraceSource(traceSourceName);
     _configuration = new TraceContextConfiguration
     {
         Activity = true,
         Trace    = false,
         BufferizeCatchExceptionAndFlash = false,
         Configs = new Dictionary <string, string>()
     };
     _header      = "DefaultContext";
     _traceBuffer = new TraceBuffer((message, eventType, date) => _traceSource.TraceEvent(eventType, 0,
                                                                                          string.Format("{0} Trace ({1}):{2}", _header, date.ToString(CultureInfo.InvariantCulture), message)));
     if (!_configuration.BufferizeCatchExceptionAndFlash)
     {
         _trace = (m, e) => _traceSource.TraceEvent(e, 0, string.Format("{0} Trace {1}", _header, m));
     }
     else
     {
         _trace = (m, e) => _traceBuffer.Trace(m, e);
     }
 }