LoggingEventSource 类

定义

LoggingEventSource 是连接所有基于 ILogger 的日志记录和 EventSource/EventListener 日志记录的桥。The LoggingEventSource is the bridge from all ILogger based logging to EventSource/EventListener logging.

public ref class LoggingEventSource sealed : System::Diagnostics::Tracing::EventSource
[System.Diagnostics.Tracing.EventSource(Name="Microsoft-Extensions-Logging")]
public sealed class LoggingEventSource : System.Diagnostics.Tracing.EventSource
[<System.Diagnostics.Tracing.EventSource(Name="Microsoft-Extensions-Logging")>]
type LoggingEventSource = class
    inherit EventSource
Public NotInheritable Class LoggingEventSource
Inherits EventSource
继承
LoggingEventSource
属性

示例

下面的示例演示如何使用 EventListener 获取 ILogging 信息:The following 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 即可启用此日志记录 Microsoft-Extensions-LoggingYou turn this logging on by enabling the EventSource called Microsoft-Extensions-Logging.

启用 EventSource 后,你设置的 EventLevel 将以明显的方式转换为与 ILogger 关联的级别(因此 Debug = verbose,信息 = 信息性 .。。严重 = = 严重)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 straightforward way.

为了更好地控制,可以指定名为的 EventSource 参数 FilterSpecsFor finer control you can specify a EventSource Argument called FilterSpecs.

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).

其中 Name 是 ILoggger 的名称(重要情况),名称可以有一个作为 * 后缀的通配符。Where Name is the name of a ILoggger (case matters), Name can have a * which acts as a wildcard AS A SUFFIX. 因此,Net * 将匹配以 "Net" 开头的所有记录器。Thus, Net* will match any loggers that start with the 'Net'.

LEVEL 为数字或 LogLevel 字符串。The LEVEL is a number or a LogLevel string. 0 = 跟踪,1 = 调试,2 = 信息,3 = 警告,4 = 错误,严重 = 5,指定关联模式的级别。0=Trace, 1=Debug, 2=Information, 3=Warning, 4=Error, Critical=5 This specifies the level for the associated pattern. 如果未指定数字(规范的第一种形式),则为 EventSource 的默认级别。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 particular name matches more than one pattern.

除了 level 和 FilterSpec 参数外,还可以设置 EventSource 关键字。In addition to 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-你使用分析窗体中的数据获取事件,但作为 JSON blob (未按参数 ...)Keywords.JsonMessage - you get an event with the data in parse form but as a JSON blob (not broken up by argument ...)
  • FormattedMessage-获取带有格式为字符串的数据的事件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.

属性

ConstructionException

获取在事件源的构造过程中引发的任何异常。Gets any exception that was thrown during the construction of the event source.

(继承自 EventSource)
Guid

此事件源的唯一标识符。The unique identifier for the event source.

(继承自 EventSource)
Name

从事件源中派生出来的类的友好名称。The friendly name of the class that is derived from the event source.

(继承自 EventSource)
Settings

获取应用于此事件源的设置。Gets the settings applied to this event source.

(继承自 EventSource)

方法

Dispose()

释放 EventSource 类的当前实例所使用的所有资源。Releases all resources used by the current instance of the EventSource class.

(继承自 EventSource)
Dispose(Boolean)

释放 EventSource 类使用的非托管资源,并可以选择释放托管资源。Releases the unmanaged resources used by the EventSource class and optionally releases the managed resources.

(继承自 EventSource)
Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsEnabled()

确定是否已启用当前事件源。Determines whether the current event source is enabled.

(继承自 EventSource)
IsEnabled(EventLevel, EventKeywords)

确定是否已启用具有指定级别和关键字的当前事件源。Determines whether the current event source that has the specified level and keyword is enabled.

(继承自 EventSource)
IsEnabled(EventLevel, EventKeywords, EventChannel)

确定是否对带有指定级别、关键字和通道的事件启用了当前事件源。Determines whether the current event source is enabled for events with the specified level, keywords and channel.

(继承自 EventSource)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnEventCommand(EventCommandEventArgs)

当该控制器更新当前事件源时调用。Called when the current event source is updated by the controller.

(继承自 EventSource)
ToString()

获得当前事件源实例的字符串表示形式。Obtains a string representation of the current event source instance.

(继承自 EventSource)
Write(String)

使用指定的名称和默认选项而非字段来写入事件。Writes an event without fields, but with the specified name and default options.

(继承自 EventSource)
Write(String, EventSourceOptions)

使用指定的名称和选项而非字段来写入事件。Writes an event without fields, but with the specified name and options.

(继承自 EventSource)
Write<T>(String, EventSourceOptions, Guid, Guid, T)

使用指定的名称、选项、相关活动和事件数据写入事件。Writes an event with the specified name, options, related activity and event data.

(继承自 EventSource)
Write<T>(String, EventSourceOptions, T)

使用指定的名称、事件数据和选项写入事件。Writes an event with the specified name, event data and options.

(继承自 EventSource)
Write<T>(String, EventSourceOptions, T)

使用指定的名称、选项和事件数据写入事件。Writes an event with the specified name, options and event data.

(继承自 EventSource)
Write<T>(String, T)

使用指定的名称和数据写入事件。Writes an event with the specified name and data.

(继承自 EventSource)
WriteEvent(Int32)

通过使用提供的事件标识符写入事件。Writes an event by using the provided event identifier.

(继承自 EventSource)
WriteEvent(Int32, Byte[])

通过使用提供的事件标识符和字节数组自变量写入事件。Writes an event by using the provided event identifier and byte array argument.

(继承自 EventSource)
WriteEvent(Int32, Int32)

通过使用提供的事件标识符和 32 位整数参数写入事件。Writes an event by using the provided event identifier and 32-bit integer argument.

(继承自 EventSource)
WriteEvent(Int32, Int32, Int32)

通过使用提供的事件标识符和 32 位整数参数写入事件。Writes an event by using the provided event identifier and 32-bit integer arguments.

(继承自 EventSource)
WriteEvent(Int32, Int32, Int32, Int32)

通过使用提供的事件标识符和 32 位整数参数写入事件。Writes an event by using the provided event identifier and 32-bit integer arguments.

(继承自 EventSource)
WriteEvent(Int32, Int32, String)

使用提供的事件标识符、32 位整数和字符串自变量写入事件。Writes an event by using the provided event identifier and 32-bit integer and string arguments.

(继承自 EventSource)
WriteEvent(Int32, Int64)

通过使用提供的事件标识符和 64 位整数自变量写入事件。Writes an event by using the provided event identifier and 64-bit integer argument.

(继承自 EventSource)
WriteEvent(Int32, Int64, Byte[])

使用指定的标识符、64 位整数和字节数组参数写入事件数据。Writes the event data using the specified identifier and 64-bit integer and byte array arguments.

(继承自 EventSource)
WriteEvent(Int32, Int64, Int64)

通过使用提供的事件标识符和 64 位参数写入事件。Writes an event by using the provided event identifier and 64-bit arguments.

(继承自 EventSource)
WriteEvent(Int32, Int64, Int64, Int64)

通过使用提供的事件标识符和 64 位参数写入事件。Writes an event by using the provided event identifier and 64-bit arguments.

(继承自 EventSource)
WriteEvent(Int32, Int64, String)

使用提供的事件标识符、64 位整数和字符串自变量写入事件。Writes an event by using the provided event identifier and 64-bit integer, and string arguments.

(继承自 EventSource)
WriteEvent(Int32, Object[])

通过使用提供的事件标识符和自变量数组写入事件。Writes an event by using the provided event identifier and array of arguments.

(继承自 EventSource)
WriteEvent(Int32, String)

通过使用提供的事件标识符和字符串自变量写入事件。Writes an event by using the provided event identifier and string argument.

(继承自 EventSource)
WriteEvent(Int32, String, Int32)

通过使用提供的事件标识符和自变量写入事件。Writes an event by using the provided event identifier and arguments.

(继承自 EventSource)
WriteEvent(Int32, String, Int32, Int32)

通过使用提供的事件标识符和自变量写入事件。Writes an event by using the provided event identifier and arguments.

(继承自 EventSource)
WriteEvent(Int32, String, Int64)

通过使用提供的事件标识符和自变量写入事件。Writes an event by using the provided event identifier and arguments.

(继承自 EventSource)
WriteEvent(Int32, String, String)

通过使用提供的事件标识符和字符串自变量写入事件。Writes an event by using the provided event identifier and string arguments.

(继承自 EventSource)
WriteEvent(Int32, String, String, String)

通过使用提供的事件标识符和字符串自变量写入事件。Writes an event by using the provided event identifier and string arguments.

(继承自 EventSource)
WriteEventCore(Int32, Int32, EventSource+EventData*)

通过使用提供的事件标识符和事件数据,创建新的 WriteEvent 重载。Creates a new WriteEvent overload by using the provided event identifier and event data.

(继承自 EventSource)
WriteEventWithRelatedActivityId(Int32, Guid, Object[])

写入一个指示当前活动与其他活动相关的事件。Writes an event that indicates that the current activity is related to another activity.

(继承自 EventSource)
WriteEventWithRelatedActivityIdCore(Int32, Guid*, Int32, EventSource+EventData*)

写入一个指示当前活动与其他活动相关的事件。Writes an event that indicates that the current activity is related to another activity.

(继承自 EventSource)

事件

EventCommandExecuted

当命令来自事件侦听器时出现。Occurs when a command comes from an event listener.

(继承自 EventSource)

适用于