LoggingEventSource LoggingEventSource Class

Definition

The LoggingEventSource is the bridge form all ILogger based logging to EventSource/EventListener logging.

You turn this logging on by enabling the EvenSource called

 Microsoft-Extensions-Logging

When you enabled the EventSource, the EventLevel you set is translated in the obvious way to the level associated with the ILogger (thus Debug = verbose, Informational = Informational ... Critical == Critical)

This allows you to filter by event level in a straighforward way.

For finer control you can specify a EventSource Argument called

FilterSpecs

The FilterSpecs argument is a semicolon separated list of specifications. Where each specification is

SPEC = // empty spec, same as * | NAME // Just a name the level is the default level | NAME : LEVEL // specifies level for a particular logger (can have a * suffix).

Where Name is the name of a ILoggger (case matters), Name can have a * which acts as a wildcard AS A SUFFIX. Thus Net* will match any loggers that start with the 'Net'.

The LEVEL is a number or a LogLevel string. 0=Trace, 1=Debug, 2=Information, 3=Warning, 4=Error, Critical=5 This speicifies the level for the associated pattern. If the number is not specified, (first form of the specification) it is the default level for the EventSource.

First match is used if a partciular name matches more than one pattern.

In addition the level and FilterSpec argument, you can also set EventSource Keywords. See the Keywords definition below, but basically you get to decide if you wish to have

  • Keywords.Message - You get the event with the data in parsed form.
  • Keywords.JsonMessage - you get an event with the data in parse form but as a JSON blob (not broken up by argument ...)
  • Keywords.FormattedMessage - you get an event with the data formatted as a string

It is expected that you will turn only one of these keywords on at a time, but you can turn them all on (and get the same data logged three different ways.

Example Usage

This example shows how to use an EventListener to get ILogging information

class MyEventListener : EventListener { protected override void OnEventSourceCreated(EventSource eventSource) { if (eventSource.Name == "Microsoft-Extensions-Logging") { // initialize a string, string dictionary of arguments to pass to the EventSource. // Turn on loggers matching App* to Information, everything else () is the default level (which is EventLevel.Error) var args = new Dictionary<string, string>() { { "FilterSpecs", "App:Information;*" } }; // Set the default level (verbosity) to Error, and only ask for the formatted messages in this case. EnableEvents(eventSource, EventLevel.Error, LoggingEventSource.Keywords.FormattedMessage, args); } } protected override void OnEventWritten(EventWrittenEventArgs eventData) { // Look for the formatted message event, which has the following argument layout (as defined in the LoggingEventSource. // FormattedMessage(LogLevel Level, int FactoryID, string LoggerName, string EventId, string FormattedMessage); if (eventData.EventName == "FormattedMessage") Console.WriteLine("Logger {0}: {1}", eventData.Payload[2], eventData.Payload[4]); } }

[EventSource(Name = "Microsoft-Extensions-Logging")]
public class LoggingEventSource : EventSource, IDisposable
<EventSource(Name:="Microsoft-Extensions-Logging")>
Public Class LoggingEventSource
    Inherits EventSource
    Implements IDisposable
Inheritance
LoggingEventSourceLoggingEventSource
Attributes
Implements

Methods

ConstructionException ConstructionException

Inherited from EventSource

CurrentThreadActivityId CurrentThreadActivityId

Inherited from EventSource

Dispose() Dispose()

Inherited from EventSource

Dispose(Boolean) Dispose(Boolean)

Inherited from EventSource

Equals(Object) Equals(Object)

Inherited from Object

Equals(Object, Object) Equals(Object, Object)

Inherited from Object

GenerateManifest(Type, String) GenerateManifest(Type, String)

Inherited from EventSource

GetGuid(Type) GetGuid(Type)

Inherited from EventSource

GetHashCode() GetHashCode()

Inherited from Object

GetName(Type) GetName(Type)

Inherited from EventSource

GetSources() GetSources()

Inherited from EventSource

GetType() GetType()

Inherited from Object

Guid Guid

Inherited from EventSource

IsEnabled() IsEnabled()

Inherited from EventSource

IsEnabled(EventLevel, EventKeywords) IsEnabled(EventLevel, EventKeywords)

Inherited from EventSource

MemberwiseClone() MemberwiseClone()

Inherited from Object

Name Name

Inherited from EventSource

OnEventCommand(EventCommandEventArgs) OnEventCommand(EventCommandEventArgs)

protected override void OnEventCommand(EventCommandEventArgs command)
Protected Overrides Sub OnEventCommand(command As EventCommandEventArgs)
Parameters
Overrides
System.Diagnostics.Tracing.EventSource.OnEventCommand(System.Diagnostics.Tracing.EventCommandEventArgs)System.Diagnostics.Tracing.EventSource.OnEventCommand(System.Diagnostics.Tracing.EventCommandEventArgs)

ReferenceEquals(Object, Object) ReferenceEquals(Object, Object)

Inherited from Object

SendCommand(EventSource, EventCommand, IDictionary) SendCommand(EventSource, EventCommand, IDictionary(Of String, String))

Inherited from EventSource

SetCurrentThreadActivityId(Guid) SetCurrentThreadActivityId(Guid)

Inherited from EventSource

SetCurrentThreadActivityId(Guid, Guid) SetCurrentThreadActivityId(Guid, Guid)

Inherited from EventSource

ToString() ToString()

Inherited from EventSource

WriteEvent(Int32) WriteEvent(Int32)

Inherited from EventSource

WriteEvent(Int32, Int32) WriteEvent(Int32, Int32)

Inherited from EventSource

WriteEvent(Int32, Int32, Int32) WriteEvent(Int32, Int32, Int32)

Inherited from EventSource

WriteEvent(Int32, Int32, Int32, Int32) WriteEvent(Int32, Int32, Int32, Int32)

Inherited from EventSource

WriteEvent(Int32, Int64) WriteEvent(Int32, Int64)

Inherited from EventSource

WriteEvent(Int32, Int64, Int64) WriteEvent(Int32, Int64, Int64)

Inherited from EventSource

WriteEvent(Int32, Int64, Int64, Int64) WriteEvent(Int32, Int64, Int64, Int64)

Inherited from EventSource

WriteEvent(Int32, Object[]) WriteEvent(Int32, Object())

Inherited from EventSource

WriteEvent(Int32, String) WriteEvent(Int32, String)

Inherited from EventSource

WriteEvent(Int32, String, Int32) WriteEvent(Int32, String, Int32)

Inherited from EventSource

WriteEvent(Int32, String, Int32, Int32) WriteEvent(Int32, String, Int32, Int32)

Inherited from EventSource

WriteEvent(Int32, String, Int64) WriteEvent(Int32, String, Int64)

Inherited from EventSource

WriteEvent(Int32, String, String) WriteEvent(Int32, String, String)

Inherited from EventSource

WriteEvent(Int32, String, String, String) WriteEvent(Int32, String, String, String)

Inherited from EventSource

WriteEventCore(Int32, Int32, EventSource.EventData*) WriteEventCore(Int32, Int32, EventSource.EventData*)

Inherited from EventSource

WriteEventWithRelatedActivityId(Int32, Guid, Object[]) WriteEventWithRelatedActivityId(Int32, Guid, Object())

Inherited from EventSource

WriteEventWithRelatedActivityIdCore(Int32, Guid*, Int32, EventSource.EventData*) WriteEventWithRelatedActivityIdCore(Int32, Guid*, Int32, EventSource.EventData*)

Inherited from EventSource