LoggingEventSource Třída
Definice
LoggingEventSource je most ze všech protokolování založených na ILogger do protokolování EventSource/naslouchacího procesu událostí.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
- Dědičnost
- Atributy
Příklady
Následující příklad ukazuje, jak použít naslouchacího procesu událostí k získání informací o 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]);
}
}
Poznámky
Toto přihlášení zapnete povolením volání EventSource Microsoft-Extensions-Logging .You turn this logging on by enabling the EventSource called Microsoft-Extensions-Logging.
Pokud jste povolili EventSource, je EventLevel, který jste nastavili, přeložena zjevným způsobem na úroveň přidruženou k ILogger (tedy Debug = verbose, informativní = informativní... Kritické = = kritické)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)
To vám umožní jednoduše filtrovat podle úrovně události.This allows you to filter by event level in a straightforward way.
Pro jemnější řízení můžete zadat argument EventSource s názvem FilterSpecs .For finer control you can specify a EventSource Argument called FilterSpecs.
FilterSpecsArgument je seznam specifikací oddělených středníkem.The FilterSpecs argument is a semicolon separated list of specifications. Kde každá specifikace jeWhere 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).
Kde name je název ILoggger (případové věci), může mít název, * který funguje jako zástupný znak jako přípona.Where Name is the name of a ILoggger (case matters), Name can have a * which acts as a wildcard AS A SUFFIX. Proto síť * bude odpovídat všem protokolovacím nástrojům, které začínají na ' NET '.Thus, Net* will match any loggers that start with the 'Net'.
ÚROVEŇ je číslo nebo řetězec LogLevel.The LEVEL is a number or a LogLevel string. 0 = trasování, 1 = ladění, 2 = informace, 3 = upozornění, 4 = chyba, kritická = 5, určuje úroveň přidruženého vzoru.0=Trace, 1=Debug, 2=Information, 3=Warning, 4=Error, Critical=5 This specifies the level for the associated pattern. Pokud číslo není zadáno, (první forma specifikace) je výchozí úroveň pro EventSource.If the number is not specified, (first form of the specification) it is the default level for the EventSource.
První shoda se používá, pokud konkrétní název odpovídá více než jednomu vzoru.First match is used if a particular name matches more than one pattern.
Kromě argumentu Level a FilterSpec můžete také nastavit klíčová slova EventSource.In addition to the level and FilterSpec argument, you can also set EventSource Keywords. Viz definice klíčových slov níže, ale v podstatě se můžete rozhodnout, jestli chcete mítSee the Keywords definition below, but basically you get to decide if you wish to have
- Klíčová slova (Keywords). Message – událost se zobrazí ve formuláři analyzovaných dat.Keywords.Message - You get the event with the data in parsed form.
- Keywords.Js-Message – získáte událost s daty ve formuláři Parse, ale jako objekt BLOB JSON (nepracuje v argumentu...).Keywords.JsonMessage - you get an event with the data in parse form but as a JSON blob (not broken up by argument ...)
- Keywords. FormattedMessage – dostanete událost s daty formátovanými jako řetězec.Keywords.FormattedMessage - you get an event with the data formatted as a string
Očekává se, že budete v jednu chvíli měnit jenom jedno z těchto klíčových slov, ale můžete je zapnout a získat stejné údaje, které se budou zaprotokolovanými třemi různými způsoby.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.
Vlastnosti
| ConstructionException |
Získá všechny výjimky, které byly vyvolány během konstrukce zdroje události.Gets any exception that was thrown during the construction of the event source. (Zděděno od EventSource) |
| Guid |
Jedinečný identifikátor pro zdroj události.The unique identifier for the event source. (Zděděno od EventSource) |
| Name |
Popisný název třídy, která je odvozena ze zdroje události.The friendly name of the class that is derived from the event source. (Zděděno od EventSource) |
| Settings |
Získá nastavení použitá pro tento zdroj události.Gets the settings applied to this event source. (Zděděno od EventSource) |
Metody
| Dispose() |
Uvolní všechny prostředky používané aktuální instancí EventSource třídy.Releases all resources used by the current instance of the EventSource class. (Zděděno od EventSource) |
| Dispose(Boolean) |
Uvolní nespravované prostředky používané EventSource třídou a volitelně uvolňuje spravované prostředky.Releases the unmanaged resources used by the EventSource class and optionally releases the managed resources. (Zděděno od EventSource) |
| Equals(Object) |
Určí, zda se zadaný objekt rovná aktuálnímu objektu.Determines whether the specified object is equal to the current object. (Zděděno od Object) |
| GetHashCode() |
Slouží jako výchozí funkce hash.Serves as the default hash function. (Zděděno od Object) |
| GetType() |
Získá Type aktuální instanci.Gets the Type of the current instance. (Zděděno od Object) |
| IsEnabled() |
Určuje, zda je aktuální zdroj události povolen.Determines whether the current event source is enabled. (Zděděno od EventSource) |
| IsEnabled(EventLevel, EventKeywords) |
Určuje, zda je aktuální zdroj události se zadanou úrovní a klíčovým slovem povolen.Determines whether the current event source that has the specified level and keyword is enabled. (Zděděno od EventSource) |
| IsEnabled(EventLevel, EventKeywords, EventChannel) |
Určuje, zda je aktuální zdroj událostí povolen pro události se zadanou úrovní, klíčovými slovy a kanálem.Determines whether the current event source is enabled for events with the specified level, keywords and channel. (Zděděno od EventSource) |
| MemberwiseClone() |
Vytvoří kopii aktuálního seznamu Object .Creates a shallow copy of the current Object. (Zděděno od Object) |
| OnEventCommand(EventCommandEventArgs) |
Volá se, když se aktuální zdroj události aktualizuje řadičem.Called when the current event source is updated by the controller. (Zděděno od EventSource) |
| ToString() |
Získá řetězcovou reprezentaci aktuální instance zdroje události.Obtains a string representation of the current event source instance. (Zděděno od EventSource) |
| Write(String) |
Zapisuje událost bez polí, ale se zadaným názvem a výchozími možnostmi.Writes an event without fields, but with the specified name and default options. (Zděděno od EventSource) |
| Write(String, EventSourceOptions) |
Zapisuje událost bez polí, ale se zadaným názvem a možnostmi.Writes an event without fields, but with the specified name and options. (Zděděno od EventSource) |
| Write<T>(String, EventSourceOptions, Guid, Guid, T) |
Zapíše událost se zadaným názvem, možnostmi, souvisejícími aktivitami a daty událostí.Writes an event with the specified name, options, related activity and event data. (Zděděno od EventSource) |
| Write<T>(String, EventSourceOptions, T) |
Zapíše událost se zadaným názvem, daty a možnostmi události.Writes an event with the specified name, event data and options. (Zděděno od EventSource) |
| Write<T>(String, EventSourceOptions, T) |
Zapíše událost se zadaným názvem, možnostmi a daty události.Writes an event with the specified name, options and event data. (Zděděno od EventSource) |
| Write<T>(String, T) |
Zapíše událost se zadaným názvem a daty.Writes an event with the specified name and data. (Zděděno od EventSource) |
| WriteEvent(Int32) |
Zapíše událost pomocí poskytnutého identifikátoru události.Writes an event by using the provided event identifier. (Zděděno od EventSource) |
| WriteEvent(Int32, Byte[]) |
Zapíše událost pomocí zadaného identifikátoru události a argumentu bajtového pole.Writes an event by using the provided event identifier and byte array argument. (Zděděno od EventSource) |
| WriteEvent(Int32, Int32) |
Zapíše událost pomocí zadaného identifikátoru události a 32 celočíselného argumentu.Writes an event by using the provided event identifier and 32-bit integer argument. (Zděděno od EventSource) |
| WriteEvent(Int32, Int32, Int32) |
Zapisuje událost pomocí zadaného identifikátoru události a 32 celočíselných argumentů.Writes an event by using the provided event identifier and 32-bit integer arguments. (Zděděno od EventSource) |
| WriteEvent(Int32, Int32, Int32, Int32) |
Zapisuje událost pomocí zadaného identifikátoru události a 32 celočíselných argumentů.Writes an event by using the provided event identifier and 32-bit integer arguments. (Zděděno od EventSource) |
| WriteEvent(Int32, Int32, String) |
Zapisuje událost pomocí zadaného identifikátoru události a 32 celočíselných argumentů a argumentů řetězce.Writes an event by using the provided event identifier and 32-bit integer and string arguments. (Zděděno od EventSource) |
| WriteEvent(Int32, Int64) |
Zapíše událost pomocí zadaného identifikátoru události a 64 celočíselného argumentu.Writes an event by using the provided event identifier and 64-bit integer argument. (Zděděno od EventSource) |
| WriteEvent(Int32, Int64, Byte[]) |
Zapíše data události pomocí zadaného identifikátoru a 64 celočíselného argumentu a argumentů pole bajtů.Writes the event data using the specified identifier and 64-bit integer and byte array arguments. (Zděděno od EventSource) |
| WriteEvent(Int32, Int64, Int64) |
Zapíše událost pomocí poskytnutého identifikátoru události a 64 argumentů.Writes an event by using the provided event identifier and 64-bit arguments. (Zděděno od EventSource) |
| WriteEvent(Int32, Int64, Int64, Int64) |
Zapíše událost pomocí poskytnutého identifikátoru události a 64 argumentů.Writes an event by using the provided event identifier and 64-bit arguments. (Zděděno od EventSource) |
| WriteEvent(Int32, Int64, String) |
Zapisuje událost pomocí zadaného identifikátoru události a 64ho celého čísla a řetězcových argumentů.Writes an event by using the provided event identifier and 64-bit integer, and string arguments. (Zděděno od EventSource) |
| WriteEvent(Int32, Object[]) |
Zapíše událost pomocí poskytnutého identifikátoru události a pole argumentů.Writes an event by using the provided event identifier and array of arguments. (Zděděno od EventSource) |
| WriteEvent(Int32, String) |
Zapíše událost pomocí zadaného identifikátoru události a argumentu řetězce.Writes an event by using the provided event identifier and string argument. (Zděděno od EventSource) |
| WriteEvent(Int32, String, Int32) |
Zapíše událost pomocí poskytnutého identifikátoru a argumentů události.Writes an event by using the provided event identifier and arguments. (Zděděno od EventSource) |
| WriteEvent(Int32, String, Int32, Int32) |
Zapíše událost pomocí poskytnutého identifikátoru a argumentů události.Writes an event by using the provided event identifier and arguments. (Zděděno od EventSource) |
| WriteEvent(Int32, String, Int64) |
Zapíše událost pomocí poskytnutého identifikátoru a argumentů události.Writes an event by using the provided event identifier and arguments. (Zděděno od EventSource) |
| WriteEvent(Int32, String, String) |
Zapíše událost pomocí poskytnutého identifikátoru události a argumentů řetězce.Writes an event by using the provided event identifier and string arguments. (Zděděno od EventSource) |
| WriteEvent(Int32, String, String, String) |
Zapíše událost pomocí poskytnutého identifikátoru události a argumentů řetězce.Writes an event by using the provided event identifier and string arguments. (Zděděno od EventSource) |
| WriteEventCore(Int32, Int32, EventSource+EventData*) |
Vytvoří nové WriteEvent přetížení pomocí poskytnutého identifikátoru události a dat události.Creates a new WriteEvent overload by using the provided event identifier and event data. (Zděděno od EventSource) |
| WriteEventWithRelatedActivityId(Int32, Guid, Object[]) |
Zapíše událost, která indikuje, že aktuální aktivita souvisí s jinou aktivitou.Writes an event that indicates that the current activity is related to another activity. (Zděděno od EventSource) |
| WriteEventWithRelatedActivityIdCore(Int32, Guid*, Int32, EventSource+EventData*) |
Zapíše událost, která indikuje, že aktuální aktivita souvisí s jinou aktivitou.Writes an event that indicates that the current activity is related to another activity. (Zděděno od EventSource) |
Události
| EventCommandExecuted |
Vyvolá se v případě, že příkaz pochází z naslouchacího procesu události.Occurs when a command comes from an event listener. (Zděděno od EventSource) |