public void TraceData(TraceEventType eventType, int id, LogEntry logEntry, TraceListenerFilter traceListenerFilter) { if (!ShouldTrace(eventType)) { return; } foreach (TraceListener listener in traceListenerFilter.GetAvailableTraceListeners(traceListeners)) { try { if (!listener.IsThreadSafe) { Monitor.Enter(listener); } listener.TraceData(manager, Name, eventType, id, logEntry); instrumentationProvider.FireTraceListenerEntryWrittenEvent(); listener.Flush(); } finally { if (!listener.IsThreadSafe) { Monitor.Exit(listener); } } } }
/// <summary> /// Delivers the trace data as an event. /// </summary> /// <param name="eventCache">The context information provided by <see cref="System.Diagnostics"/>.</param> /// <param name="source">The name of the trace source that delivered the trace data.</param> /// <param name="eventType">The type of event.</param> /// <param name="id">The id of the event.</param> /// <param name="data">The data to trace.</param> public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data) { if (data is LogEntry) { ManagementInstrumentation.Fire(data as LogEntry); instrumentationProvider.FireTraceListenerEntryWrittenEvent(); } else if (data is string) { Write(data); } else { base.TraceData(eventCache, source, eventType, id, data); } }
/// <summary> /// Intercepts the tracing request to format the object to trace. /// </summary> /// <remarks> /// Formatting is only performed if the object to trace is a <see cref="LogEntry"/> and the formatter is set. /// </remarks> /// <param name="eventCache">The context information.</param> /// <param name="source">The trace source.</param> /// <param name="eventType">The severity.</param> /// <param name="id">The event id.</param> /// <param name="data">The object to trace.</param> public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data) { if (data is LogEntry) { if (this.Formatter != null) { base.Write(this.Formatter.Format(data as LogEntry)); } else { base.TraceData(eventCache, source, eventType, id, data); } InstrumentationProvider.FireTraceListenerEntryWrittenEvent(); } else { base.TraceData(eventCache, source, eventType, id, data); } }
/// <summary> /// Writes trace data to the trace listeners in the <see cref="LogSource.Listeners"/> collection that have not already been /// written to for tracing using the specified event type, event identifier, and trace data. /// </summary> /// <remarks> /// The <paramref name="traceListenerFilter"/> will be updated to reflect the trace listeners that were written to by the /// <see cref="LogSource"/>. /// </remarks> /// <param name="eventType">The value that specifies the type of event that caused the trace.</param> /// <param name="id">A numeric identifier for the event.</param> /// <param name="logEntry">The <see cref="LogEntry"/> to trace.</param> /// <param name="traceListenerFilter">The filter for already written to trace listeners.</param> public void TraceData(TraceEventType eventType, int id, LogEntry logEntry, TraceListenerFilter traceListenerFilter) { if (!ShouldTrace(eventType)) { return; } TraceEventCache manager = new TraceEventCache(); bool isTransfer = logEntry.Severity == TraceEventType.Transfer && logEntry.RelatedActivityId != null; foreach (TraceListener listener in traceListenerFilter.GetAvailableTraceListeners(traceListeners)) { try { if (!listener.IsThreadSafe) { Monitor.Enter(listener); } if (!isTransfer) { listener.TraceData(manager, Name, eventType, id, logEntry); } else { listener.TraceTransfer(manager, Name, id, logEntry.Message, logEntry.RelatedActivityId.Value); } instrumentationProvider.FireTraceListenerEntryWrittenEvent(); listener.Flush(); } finally { if (!listener.IsThreadSafe) { Monitor.Exit(listener); } } } }