public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
 {
     if (data is LogEntry)
     {
         this.Write(baseModel.Serialize(new LogMessageModel(data as LogEntry)).DocumentElement.OuterXml);
     }
 }
 public void ThreadIdTest()
 {
     var cache = new TraceEventCache();
     var id = cache.ThreadId;
     Assert.NotNull(id);
     Assert.NotEqual("", id);
 }
 public void ShouldTrace()
 {
     var cache = new TraceEventCache();
     var filter = new EventTypeFilter(SourceLevels.Error);
     Assert.True(filter.ShouldTrace(cache, null, TraceEventType.Critical, 0, null, null, null, null));
     Assert.False(filter.ShouldTrace(cache, null, TraceEventType.Warning, 0, null, null, null, null));
 }
 public void ProcessIdTest()
 {
     var cache = new TraceEventCache();
     var id = cache.ProcessId;
     var expected = System.Diagnostics.Process.GetCurrentProcess().Id;
     Assert.Equal((int)expected, id);
 }
 public void TimestampTest()
 {
     var cache = new TraceEventCache();
     var dt1 = cache.Timestamp;
     var dt2 = cache.Timestamp;
     Assert.Equal(dt1, dt2);
 }
示例#6
0
 public void ShouldTraceTest()
 {
     var sourceName = "TestSource";
     var cache = new TraceEventCache();
     var filter = new SourceFilter(sourceName);
     Assert.True(filter.ShouldTrace(cache, sourceName, TraceEventType.Critical, 0, null, null, null, null));
     Assert.False(filter.ShouldTrace(cache, "Default", TraceEventType.Warning, 0, null, null, null, null));
     Assert.Throws<ArgumentNullException>(() => filter.ShouldTrace(cache, null, TraceEventType.Warning, 0, null, null, null, null));
 }
 public void DateTimePropertyTest()
 {
     var cache = new TraceEventCache();
     var begin = DateTime.UtcNow;
     var dt = cache.DateTime;
     var end = DateTime.UtcNow;
     Assert.True(dt >= begin);
     Assert.True(dt <= end);
     var cached = cache.DateTime;
     Assert.Equal(dt, cached);
 }
        public void TraceEvent_FormatString_Test(TraceFilter filter, TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, object[] args)
        {
            using (var target = new DelimitedListTraceListener(_stream))
            {
                target.Filter = filter;
                target.TraceOutputOptions = TraceOptions.ProcessId | TraceOptions.ThreadId | TraceOptions.DateTime | TraceOptions.Timestamp;
                target.TraceEvent(eventCache, source, eventType, id, format, args);
            }

            string expected = CommonUtilities.ExpectedTraceEventOutput(filter, eventCache, source, eventType, id, format, args);
            Assert.Equal(expected, File.ReadAllText(_fileName));
        }
示例#9
0
        internal static string ExpectedTraceEventOutput(TraceFilter filter, TraceEventCache cache, string source, TraceEventType eventType, int id, string format, object[] args)
        {
            if (filter != null && !filter.ShouldTrace(cache, source, eventType, id, format, args, null, null))
                return string.Empty;

            var builder = new StringBuilder();
            builder.AppendHeader(source, eventType, id);
            builder.Append(EscapedString(args != null ? string.Format(format, args) : format));
            builder.Append(DefaultDelimiter);
            builder.Append(DefaultDelimiter);
            builder.AppendTraceEventCache(cache);
            return builder.AppendLine().ToString();
        }
示例#10
0
        internal static string ExpectedTraceDataOutput(TraceFilter filter, TraceEventCache cache, string source, TraceEventType eventType, int id, object data)
        {
            if (filter != null && !filter.ShouldTrace(cache, source, eventType, id, null, null, data, null))
                return string.Empty;

            var builder = new StringBuilder();
            builder.AppendHeader(source, eventType, id);
            builder.Append(DefaultDelimiter);
            builder.Append(EscapedString(data.ToString()));
            builder.Append(DefaultDelimiter);
            builder.AppendTraceEventCache(cache);
            return builder.AppendLine().ToString();
        }
示例#11
0
 public void LogicalOperationStack()
 {
     var cache = new TraceEventCache();
     var logicalOperationStack = cache.LogicalOperationStack; 
     Assert.Equal(0, logicalOperationStack.Count);
     Trace.CorrelationManager.StartLogicalOperation("SecondaryThread");
     Trace.CorrelationManager.StartLogicalOperation("MainThread");
     Assert.NotNull(logicalOperationStack);
     Assert.Equal(2, logicalOperationStack.Count);
     Assert.Equal("MainThread", logicalOperationStack.Pop().ToString());
     Assert.Equal("SecondaryThread", logicalOperationStack.Peek().ToString());
     Trace.CorrelationManager.StopLogicalOperation();
     Assert.Equal(0, logicalOperationStack.Count);
 }
 public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
 {
     if (data is LogEntry)
     {
         // Check Channel State otherwise can generate loop errors
         if (this.proxyLogging.State == CommunicationState.Opened)
         {
             Guid guid = this.proxyLogging.LoggingExceptionSet(data as LogEntry);
         }
     }
     else
     {
         //this.WriteLine(data.ToString());
     }
 }
示例#13
0
 private static void AppendTraceEventCache(this StringBuilder builder, TraceEventCache cache, string delimiter = DefaultDelimiter)
 {
     if (cache != null)
     {
         builder.Append(cache.ProcessId);
         builder.Append(delimiter);
         builder.Append(EscapedString(cache.ThreadId));
         builder.Append(delimiter);
         builder.Append(EscapedString(cache.DateTime.ToString("o", CultureInfo.InvariantCulture)));
         builder.Append(delimiter);
         builder.Append(cache.Timestamp.ToString(CultureInfo.InvariantCulture));
         builder.Append(delimiter);
     }
     else
     {
         for (int i = 0; i < 5; ++i)
             builder.Append(delimiter);
     }
 }
示例#14
0
        internal static string ExpectedTraceDataOutput(string delimiter, TraceFilter filter, TraceEventCache cache, string source, TraceEventType eventType, int id, object[] data)
        {
            if (filter != null && !filter.ShouldTrace(cache, source, eventType, id, null, null, data, null))
                return string.Empty;

            string secondDelimiter = delimiter == "," ? DefaultDelimiter : ",";
            var builder = new StringBuilder();
            builder.AppendHeader(source, eventType, id, delimiter);
            builder.Append(delimiter);
            if (data != null)
            {
                for (int i = 0; i < data.Length; ++i)
                {
                    if (i != 0)
                        builder.Append(secondDelimiter);
                    builder.Append(EscapedString(data[i].ToString()));
                }
            }
            builder.Append(delimiter);
            builder.AppendTraceEventCache(cache, delimiter);

            return builder.AppendLine().ToString();
        }
        public sealed override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
        {
            if (!_provider.IsEnabled())
            {
                return;
            }

            if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, null, null, null, null))
            {
                return;
            }

            if (args == null)
            {
                _provider.WriteMessageEvent(format,
                                (byte)eventType,
                                (long)eventType & s_keyWordMask);
            }
            else
            {
                _provider.WriteMessageEvent(String.Format(CultureInfo.InvariantCulture, format, args),
                                (byte)eventType,
                                (long)eventType & s_keyWordMask);
            }
        }
示例#16
0
        public override bool ShouldTrace(TraceEventCache cache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] args, object data1, object[] data)
        {
            if (!_lastEventType.ContainsKey(source))
            {
                _lastEventType.Add(source, TraceEventType.Information);
                _lastTrigger.Add(source, DateTime.MinValue);
                _currentDelay.Add(source, TimeSpan.FromSeconds(0));
            }

            if (_lastEventType[source] != eventType)
            {
                if (DelayTriggerTime.TotalSeconds > 0)
                {
                    if (_lastEventType[source] != TraceEventType.Critical && eventType != TraceEventType.Critical)
                    {
                        if (eventType != TraceEventType.Information)
                        {
                            // Remember when we last had a bad state
                            //  - We only come here when have been in good state for a "long" time
                            _lastEventType[source] = eventType;
                            _lastTrigger[source]   = DateTime.UtcNow;
                            _currentDelay[source]  = DelayTriggerTime;
                        }
                        else
                        {
                            // We stay in bad state until enough time has passed
                            if (DateTime.UtcNow.Subtract(_lastTrigger[source]) < DelayTriggerTime)
                            {
                                return(false);
                            }

                            // Clear bad state
                            _lastTrigger[source]   = DateTime.UtcNow;
                            _lastEventType[source] = eventType;

                            // Delay have been changed if we have entered bad-state
                            if (NextTriggerTime.TotalSeconds > 0)
                            {
                                if (_currentDelay[source] >= NextTriggerTime)
                                {
                                    System.Diagnostics.Trace.WriteLine(_configSection + ": " + source + " triggered " + eventType.ToString() + " event.");
                                    _currentDelay[source] = TimeSpan.FromSeconds(0);
                                    return(true);    // We have to clear the bad event
                                }
                            }
                            else
                            {
                                if (_currentDelay[source].TotalSeconds <= 0)
                                {
                                    System.Diagnostics.Trace.WriteLine(_configSection + ": " + source + " triggered " + eventType.ToString() + " event.");
                                    return(true);    // We have to clear the bad event
                                }
                            }
                        }
                        return(false);
                    }
                }
                _currentDelay[source]  = NextTriggerTime;
                _lastTrigger[source]   = DateTime.UtcNow;
                _lastEventType[source] = eventType;
                System.Diagnostics.Trace.WriteLine(_configSection + ": " + source + " triggered " + eventType.ToString() + " event.");
                return(true);
            }

            if (eventType == TraceEventType.Information)
            {
                return(false);
            }

            if (DelayTriggerTime.TotalSeconds > 0)
            {
                // We should only trigger again when state changes back to good
                if (NextTriggerTime.TotalSeconds <= 0 && _currentDelay[source].TotalSeconds <= 0)
                {
                    if (eventType != TraceEventType.Information)
                    {
                        _lastTrigger[source] = DateTime.UtcNow;    // Update last bad state
                    }
                    return(false);
                }
            }

            if (DateTime.UtcNow.Subtract(_lastTrigger[source]) < _currentDelay[source])
            {
                return(false);
            }

            if (NextTriggerTime.TotalSeconds > 0)
            {
                // Setup when to allow the next trigger
                _currentDelay[source] = _currentDelay[source].Add(_currentDelay[source]);
                if (_currentDelay[source] < NextTriggerTime)
                {
                    _currentDelay[source] = NextTriggerTime;
                }
            }
            else
            {
                _currentDelay[source] = TimeSpan.FromSeconds(0);    // Trigger whenever state changes
            }
            _lastTrigger[source]   = DateTime.UtcNow;
            _lastEventType[source] = eventType;
            System.Diagnostics.Trace.WriteLine(_configSection + ": " + source + " triggered " + eventType.ToString() + " event.");
            return(true);
        }
        public sealed override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id)
        {
            if (!_provider.IsEnabled())
            {
                return;
            }

            if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, null, null, null, null))
            {
                return;
            }

            _provider.WriteMessageEvent(String.Empty,
                            (byte)eventType,
                            (long)eventType & s_keyWordMask);
        }
 /// <summary>
 /// Write a trace event entry
 /// </summary>
 /// <param name="eventCache"></param>
 /// <param name="source"></param>
 /// <param name="eventType"></param>
 /// <param name="id"></param>
 /// <param name="format"></param>
 /// <param name="args"></param>
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
 {
     Log.Write(new TraceLogEntry(eventCache, source, eventType, string.Format(CultureInfo.InvariantCulture, format, args)));
 }
        // (indirectly) OnEventHookTracerOnSpanActivated
        // (indirectly) OnEventHookTracerOnSpanFinished
        // (indirectly) OnEventHookTracerOnSpanLog
        // (indirectly) OnEventHookTracerOnSpanSetTag
        public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
        {
            var dictionary = data as IDictionary <string, object>;

            if (dictionary == null)
            {
                var enumerable = data as IEnumerable <KeyValuePair <string, object> >;
                if (enumerable == null)
                {
                    // TODO: Should we throw? We don't recognize this what do we do with it?
                    // TODO: Do we just ToString it and log it?
                    // TODO: Do we delegate to the underlying TraceData output
                    base.TraceEvent(eventCache, source, TraceEventType.Error, 998,
                                    "Unrecognized captured TraceData call. Payload: " +
                                    JsonConvert.SerializeObject(data,
                                                                new JsonSerializerSettings {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                    }));
                    base.TraceData(eventCache, source, eventType, id, data);
                    return;
                }

                dictionary = enumerable.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            }

            object vectorClockObj;

            dictionary.TryGetValue(SpecialConstants.VectorClock, out vectorClockObj);
            string vectorClock = vectorClockObj?.ToString();

            object operationNameObj;

            dictionary.TryGetValue(SpecialConstants.OperationName, out operationNameObj);
            string operationName = operationNameObj?.ToString();

            switch (id)
            {
            // OnEventHookTracerOnSpanActivated
            case 1:
            // These two are mostly the same, presently.
            // OnEventHookTracerOnSpanFinished
            case 2:
                this.TraceSpanLifecycleEvent(vectorClock, operationName, eventType);

                break;

            // OnEventHookTracerOnSpanLog
            case 3:
                object eventObj;
                dictionary.TryGetValue(OpenTracingTraceListener.Constants.EventLogKey, out eventObj);
                string eventText = eventObj?.ToString();

                object traceLevelObj;
                dictionary.TryGetValue(OpenTracingTraceListener.Constants.LevelLogKey, out traceLevelObj);
                TraceEventType traceLevel = traceLevelObj == null
                        ? eventType
                        : (TraceEventType)Enum.Parse(typeof(TraceEventType), traceLevelObj?.ToString());

                object isWriteObj;
                bool   isWrite = dictionary.TryGetValue(OpenTracingTraceListener.Constants.IsWriteWithoutNewline, out isWriteObj);

                object categoryObj;
                dictionary.TryGetValue(SpecialConstants.Category, out categoryObj);
                string category = categoryObj?.ToString();

                this.TraceLog(vectorClock, traceLevel, eventText, isWrite, category, dictionary, operationName,
                              eventCache, source, id);

                break;

            // OnEventHookTracerOnSpanSetTag
            case 4:
                // Arbitrary keys
                this.TraceSetTags(vectorClock, eventType, dictionary, operationName,
                                  eventCache, source, id);
                break;
            }

            //base.TraceData(
            //    eventCache,
            //    source,
            //    eventType,
            //    id,
            //    JsonConvert.SerializeObject(data));
        }
示例#20
0
 /// <summary/>
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
 {
     TraceOut(source, eventType, id, message);
 }
示例#21
0
 /// <summary/>
 public override void TraceTransfer(TraceEventCache eventCache, string source, int id, string message, Guid relatedActivityId)
 {
     TraceOut(source, TraceEventType.Transfer, id, String.Format(CultureInfo.InvariantCulture, "Transfer Message:{0}\n ActivityID:{1}", message, relatedActivityId.ToString()));
 }
示例#22
0
 /// <summary>
 /// Writes trace information, a data object and event information to the listener specific output.
 /// </summary>
 /// <param name="eventCache">A <see cref="T:System.Diagnostics.TraceEventCache"/> object that contains the current process ID, thread ID, and stack trace information.</param>
 /// <param name="source">A name used to identify the output, typically the name of the application that generated the trace event.</param>
 /// <param name="eventType">One of the <see cref="T:System.Diagnostics.TraceEventType"/> values specifying the type of event that has caused the trace.</param>
 /// <param name="id">A numeric identifier for the event.</param>
 /// <param name="data">The trace data to emit.</param>
 public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
 {
     TraceData(eventCache, source, eventType, id, new object[] { data });
 }
示例#23
0
 public LogEntry(TraceEventCache eventCache)
 {
     Ticks    = eventCache.Timestamp;
     dateTime = eventCache.DateTime.ToLocalTime();
 }
示例#24
0
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
 {
     WriteLine(source, TraceEventType.Verbose, format, args);
 }
 public override bool ShouldTrace(TraceEventCache cache, string source,
                                  TraceEventType eventType, int id, string formatOrMessage,
                                  object[] args, object data1, object[] data)
 {
     return(formatOrMessage != null && formatOrMessage.Length < 10);
 }
示例#26
0
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
 {
     WriteLine(source, TraceEventType.Verbose, message);
 }
示例#27
0
 public override bool ShouldTrace(TraceEventCache Cache, string Source, TraceEventType EventType, int Id, string FormatOrMessage, object[] Args, object Data1, object[] Data)
 {
     return(EventType <= VerbosityLevel);
 }
 /// <summary>
 /// Write a trace event entry
 /// </summary>
 /// <param name="eventCache"></param>
 /// <param name="source"></param>
 /// <param name="eventType"></param>
 /// <param name="id"></param>
 /// <param name="message"></param>
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
 {
     Log.Write(new TraceLogEntry(eventCache, source, eventType, message));
 }
示例#29
0
        public void CallstackTest_ContainsExpectedFrames()
        {
            var cache = new TraceEventCache();

            Assert.Contains("System.Environment.get_StackTrace()", cache.Callstack);
        }
示例#30
0
        public void CallstackTest_NotEmpty()
        {
            var cache = new TraceEventCache();

            Assert.NotEmpty(cache.Callstack);
        }
示例#31
0
 /// <summary/>
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id)
 {
     TraceOut(source, eventType, id, "Parameterless TraceEvent Recorded.");
 }
        public void TraceEventTest2()
        {
            var cache = new TraceEventCache();
            var listener = new TestTextTraceListener();
            listener.Filter = new TestTraceFilter(false);
            listener.TraceEvent(cache, "Source", TraceEventType.Critical, 1, "Format", "arg1");
            Assert.Equal(0, listener.WriteCount);

            listener = new TestTextTraceListener();
            listener.TraceEvent(cache, "Source", TraceEventType.Critical, 1, "Format", "arg1");
            var expected = 2; // header and message.
            Assert.Equal(expected, listener.WriteCount);
        }
示例#33
0
 /// <summary/>
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
 {
     TraceOut(source, eventType, id, String.Format(CultureInfo.InvariantCulture, format, args));
 }
示例#34
0
 /// <summary>
 /// Return the trace event Id
 /// </summary>
 /// <param name="value">The return value, usually null if the value couldn't be read</param>
 /// <param name="cache">The <see cref="TraceEventCache"/></param>
 /// <param name="source">The source of the logging event</param>
 /// <param name="eventType">The <see cref="TraceEventType"/> of the logging event</param>
 /// <param name="id">The id of the logging event</param>
 /// <param name="formatOrMessage">The format string or complete message</param>
 /// <param name="data">The array of objects</param>
 /// <returns>True if the value could be read</returns>
 public override bool TryGetValue(out object value, TraceEventCache cache, string source,
                                  TraceEventType eventType, int id, string formatOrMessage, object[] data)
 {
     value = id;
     return(true);
 }
示例#35
0
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id)
 {
     WriteLine(id.ToString(CultureInfo.InvariantCulture));
 }
 /// <summary>
 /// Write a trace event entry
 /// </summary>
 /// <param name="eventCache"></param>
 /// <param name="source"></param>
 /// <param name="eventType"></param>
 /// <param name="id"></param>
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id)
 {
     Log.Write(new TraceLogEntry(eventCache, source, eventType, string.Empty));
 }
        internal void TraceData(
            TraceEventType eventType,
            int id,
            LogEntry logEntry,
            TraceListenerFilter traceListenerFilter,
            TraceEventCache traceEventCache,
            ReportTracingError reportError)
        {
            if (!ShouldTrace(eventType))
            {
                return;
            }

            bool isTransfer = logEntry.Severity == TraceEventType.Transfer && logEntry.RelatedActivityId != null;

            try
            {
                foreach (TraceListener listener in traceListenerFilter.GetAvailableTraceListeners(traceListeners))
                {
                    var asynchronousListener = listener as IAsynchronousTraceListener;
                    if (asynchronousListener == null)
                    {
                        try
                        {
                            if (!listener.IsThreadSafe)
                            {
                                Monitor.Enter(listener);
                            }

                            if (!isTransfer)
                            {
                                listener.TraceData(traceEventCache, this.Name, eventType, id, logEntry);
                            }
                            else
                            {
                                listener.TraceTransfer(traceEventCache, this.Name, id, logEntry.Message, logEntry.RelatedActivityId.Value);
                            }

                            if (this.AutoFlush)
                            {
                                listener.Flush();
                            }
                        }
                        finally
                        {
                            if (!listener.IsThreadSafe)
                            {
                                Monitor.Exit(listener);
                            }
                        }
                    }
                    else
                    {
                        if (!isTransfer)
                        {
                            asynchronousListener.TraceData(traceEventCache, this.Name, eventType, id, logEntry, reportError);
                        }
                        else
                        {
                            asynchronousListener.TraceTransfer(traceEventCache, this.Name, id, logEntry.Message, logEntry.RelatedActivityId.Value, reportError);
                        }

                        if (this.AutoFlush)
                        {
                            asynchronousListener.Flush(reportError);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (reportError == null)
                {
                    throw;
                }

                reportError(e, logEntry, this.name);
            }
        }
 public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, params object[] data);
        public void WriteFooterTest(TraceOptions opts, int flagCount)
        {
            var cache = new TraceEventCache();
            var listener = new TestTextTraceListener();
            listener.TraceOutputOptions = opts;
            listener.Filter = new TestTraceFilter(false);
            listener.TraceEvent(cache, "Source", TraceEventType.Critical, 1);
            Assert.Equal(0, listener.WriteCount);

            var baseExpected = 2; // header + message
            var expected = baseExpected;

            listener = new TestTextTraceListener();
            listener.TraceOutputOptions = opts;
            listener.TraceEvent(null, "Source", TraceEventType.Critical, 1);
            Assert.Equal(expected, listener.WriteCount);

            // Two calls to write per flag, one call for writing the indent, one for the message.
            expected = baseExpected + flagCount * 2;
            listener = new TestTextTraceListener();
            listener.TraceOutputOptions = opts;
            listener.TraceEvent(cache, "Source", TraceEventType.Critical, 1);
            Assert.Equal(expected, listener.WriteCount);
        }
 public abstract bool ShouldTrace(TraceEventCache cache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] args, object data1, object[] data);
示例#41
0
            public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
            {
                var color = GetColor(eventType, id);

                ColorConsole.WriteLine(color, eventCache.DateTime.ToString("[HH:mm:ss.fff] ") + format, args);
            }
 public virtual void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, object[] args)
 {
 }
 public virtual void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object[] data)
 {
 }
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id)
 {
     Log(eventType, "");
 }
示例#45
0
 public void CallstackTest()
 {
     var cache = new TraceEventCache();
     Assert.Contains("at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)", cache.Callstack);
     Assert.Contains("at System.Environment.get_StackTrace()", cache.Callstack);
 }
        /// <summary>
        /// Writes trace information, a formatted array of objects and event
        /// information to the listener specific output.
        /// </summary>
        /// <param name="eventCache">
        /// A <see cref="T:System.Diagnostics.TraceEventCache"/> object that
        /// contains the current process ID, thread ID, and stack trace
        /// information.
        /// </param>
        /// <param name="source">
        /// A name used to identify the output, typically the name of the
        /// application that generated the trace event.
        /// </param>
        /// <param name="eventType">
        /// One of the <see cref="T:System.Diagnostics.TraceEventType"/> values
        /// specifying the type of event that has caused the trace.
        /// </param>
        /// <param name="id">A numeric identifier for the event.</param>
        /// <param name="format">
        /// A format string that contains zero or more format items, which
        /// correspond to objects in the <paramref name="args"/> array.
        /// </param>
        /// <param name="args">
        /// An object array containing zero or more objects to format.
        /// </param>
        public sealed override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
        {
            TraceEventData eventData = AddCustomerIdAndSessionIdToEventDataIfTheyAreSet(new TraceEventData(eventCache, source, eventType, id));

            Trace(eventData, format, args);
        }
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args);
        /// <summary>
        /// Writes trace information, a message, and event information to the
        /// listener specific output.
        /// </summary>
        /// <param name="eventCache">
        /// A <see cref="T:System.Diagnostics.TraceEventCache"/> object that
        /// contains the current process ID, thread ID, and stack trace
        /// information.
        /// </param>
        /// <param name="source">
        /// A name used to identify the output, typically the name of the
        /// application that generated the trace event.
        /// </param>
        /// <param name="eventType">
        /// One of the <see cref="T:System.Diagnostics.TraceEventType"/> values
        /// specifying the type of event that has caused the trace.
        /// </param>
        /// <param name="id">A numeric identifier for the event.</param>
        /// <param name="message">A message to write.</param>
        public sealed override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
        {
            TraceEventData eventData = AddCustomerIdAndSessionIdToEventDataIfTheyAreSet(new TraceEventData(eventCache, source, eventType, id));

            Trace(eventData, message);
        }
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message);
示例#50
0
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
 {
     DetermineOverQuota();
     base.TraceEvent(eventCache, source, eventType, id, format, args);
 }
 public virtual void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
 {
 }
示例#52
0
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
 {
     DetermineOverQuota();
     base.TraceEvent(eventCache, source, eventType, id, message);
 }
 public virtual void TraceTransfer(TraceEventCache eventCache, string source, int id, string message, System.Guid relatedActivityId)
 {
 }
示例#54
0
 public override void TraceTransfer(TraceEventCache eventCache, string source, int id, string message, Guid relatedActivityId)
 {
     DetermineOverQuota();
     base.TraceTransfer(eventCache, source, id, message, relatedActivityId);
 }
        public sealed override void TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, int id, params object[] data)
        {
            if (!_provider.IsEnabled())
            {
                return;
            }

            if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, null, null, null, null))
            {
                return;
            }

            int index;
            StringBuilder dataString = new StringBuilder(s_defaultPayloadSize);

            if ((data != null) && (data.Length > 0))
            {
                for (index = 0; index < (data.Length - 1); index++)
                {
                    if (data[index] != null)
                    {
                        dataString.Append(data[index].ToString());
                        dataString.Append(Delimiter);
                    }
                    else
                    {
                        dataString.Append(s_nullStringComaValue);
                    }
                }

                if (data[index] != null)
                {
                    dataString.Append(data[index].ToString());
                }
                else
                {
                    dataString.Append(s_nullStringValue);
                }
            }
            else
            {
                dataString.Append(s_nullStringValue);
            }

            _provider.WriteMessageEvent(dataString.ToString(),
                            (byte)eventType,
                            (long)eventType & s_keyWordMask);
        }
示例#56
0
 public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
 {
     DetermineOverQuota();
     base.TraceData(eventCache, source, eventType, id, data);
 }
        public sealed override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
        {
            if (!_provider.IsEnabled())
            {
                return;
            }

            if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, null, null, null, null))
            {
                return;
            }

            StringBuilder dataString = new StringBuilder(s_defaultPayloadSize);
            dataString.Append(message);

            _provider.WriteMessageEvent(dataString.ToString(),
                            (byte)eventType,
                            (long)eventType & s_keyWordMask);
        }
示例#58
0
        private void TraceEventInternal(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, object[] args)
        {
            if (null == eventCache)
            {
                return;
            }
            _ = source;
            _ = id;
            // Convert eventType (an enum) back to an index so we can count the different types of error separately.
            int errorLevel = (int)(Math.Log((int)eventType) / Math.Log(2));

            if (errorLevel < eventCounts.Length)
            {
                eventCounts[errorLevel]++;
            }

            // Event is less important than error (and critical) and we're logging only errors... bail.
            if (eventType > TraceEventType.Error && errorsOnly)
            {
                return;
            }

            StringBuilder output = new StringBuilder();

            if (!lastWrittenFormatted)
            {
                output.AppendLine();
                output.AppendLine();
            }
            output.Append(eventType);
            output.Append(": ");
            if (args.Length == 0)
            {
                output.Append(format);
            }
            else
            {
                output.AppendFormat(CultureInfo.InvariantCulture, format, args);
            }

            // Log exception details if it is an exception.
            if (eventCache.LogicalOperationStack.Contains(LogicalOperationWriteException))
            {
                // Attempt to clean up the stacks; the problem is that the exception stack only goes as far back as the call made inside the try block. We also have access to the
                // full stack to this trace call, which goes via the catch block at the same level as the try block. We'd prefer to have the whole stack, so we need to find the
                // join and stitch the stacks together.
                Exception  error           = args[0] as Exception;
                StackTrace errorStack      = new StackTrace(args[0] as Exception);
                StackFrame errorStackLast  = errorStack.GetFrame(errorStack.FrameCount - 1);
                StackTrace catchStack      = new StackTrace();
                int        catchStackIndex = 0;
                while (catchStackIndex < catchStack.FrameCount && errorStackLast != null && catchStack.GetFrame(catchStackIndex).GetMethod().Name != errorStackLast.GetMethod().Name)
                {
                    catchStackIndex++;
                }
                catchStack = new StackTrace(catchStackIndex < catchStack.FrameCount ? catchStackIndex + 1 : 0, true);

                output.AppendLine(error.ToString());
                output.AppendLine(catchStack.ToString());
            }
            else
            {
                // Only log a stack trace for critical and error levels.
                if ((eventType < TraceEventType.Warning) && (TraceOutputOptions & TraceOptions.Callstack) != 0)
                {
                    output.AppendLine();
                    output.AppendLine(new StackTrace(true).ToString());
                }
            }

            output.AppendLine();
            writer.Write(output.ToString());
            lastWrittenFormatted = true;
        }
示例#59
0
 public override bool ShouldTrace(TraceEventCache cache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] args, object data1, object[] data)
 {
     return _shouldTrace;
 }
示例#60
0
 /// <summary/>
 public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
 {
     TraceOut(source, eventType, id, data);
 }