Пример #1
0
        /// <summary>
        /// Writes an <see cref="ILogEvent"/> to the provider <see cref="ILogger"/> and
        /// </summary>
        /// <param name="logger">The logger to write to.</param>
        /// <param name="logEvent">The event to be logged.</param>
        /// <param name="exception">Optional exception parameter for logging.</param>
        public static void LogDurableEvent(this ILogger logger, ILogEvent logEvent, Exception exception = null)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException(nameof(logEvent));
            }

            logger?.Log(
                logEvent.Level,
                logEvent.EventId,
                logEvent,
                exception,
                formatter: (s, e) => s.FormattedMessage);

            if (logEvent is IEventSourceEvent eventSourceEvent)
            {
                StructuredEventSource.EnsureLogicalTraceActivityId();
                eventSourceEvent.WriteEventSource();
            }
        }
Пример #2
0
 /// <summary>
 /// Sets the trace activity ID for the current logical thread.
 /// </summary>
 /// <param name="traceActivityId">The trace activity ID to set.</param>
 public static void SetLogicalTraceActivityId(Guid traceActivityId)
 {
     StructuredEventSource.SetLogicalTraceActivityId(traceActivityId);
 }