TraceSource.TraceEvent Método
Definição
Sobrecargas
| TraceEvent(TraceEventType, Int32) |
Grava uma mensagem de evento de rastreamento para os ouvintes de rastreamento na coleção Listeners usando o tipo de evento e o identificador de evento especificados.Writes a trace event message to the trace listeners in the Listeners collection using the specified event type and event identifier. |
| TraceEvent(TraceEventType, Int32, String) |
Grava uma mensagem de evento de rastreamento para os ouvintes de rastreamento na coleção Listeners usando o tipo de evento, o identificador de evento e a mensagem especificados.Writes a trace event message to the trace listeners in the Listeners collection using the specified event type, event identifier, and message. |
| TraceEvent(TraceEventType, Int32, String, Object[]) |
Grava um evento de rastreamento para os ouvintes de rastreamento na coleção Listeners usando o tipo de evento, o identificador de evento, a matriz de argumentos e o formato especificados.Writes a trace event to the trace listeners in the Listeners collection using the specified event type, event identifier, and argument array and format. |
TraceEvent(TraceEventType, Int32)
public:
void TraceEvent(System::Diagnostics::TraceEventType eventType, int id);
[System.Diagnostics.Conditional("TRACE")]
public void TraceEvent (System.Diagnostics.TraceEventType eventType, int id);
[<System.Diagnostics.Conditional("TRACE")>]
member this.TraceEvent : System.Diagnostics.TraceEventType * int -> unit
Public Sub TraceEvent (eventType As TraceEventType, id As Integer)
Parâmetros
- eventType
- TraceEventType
Um dos valores de enumeração que especifica o tipo de evento dos dados de rastreamento.One of the enumeration values that specifies the event type of the trace data.
- id
- Int32
Um identificador numérico do evento.A numeric identifier for the event.
- Atributos
Exceções
Foi feita uma tentativa de rastrear um evento durante a finalização.An attempt was made to trace an event during finalization.
Exemplos
O exemplo de código a seguir mostra o uso do TraceEvent(TraceEventType, Int32) método para passar um evento de rastreamento para os ouvintes.The following code example shows the use of the TraceEvent(TraceEventType, Int32) method to pass a trace event to the listeners. Este exemplo de código faz parte de um exemplo maior fornecido para a TraceSource classe.This code example is part of a larger example provided for the TraceSource class.
ts.TraceEvent(TraceEventType.Warning, 1);
ts.TraceEvent(TraceEventType.Warning, 1)
Comentários
O TraceEvent método destina-se a rastrear eventos que podem ser processados automaticamente por ferramentas.The TraceEvent method is intended to trace events that can be processed automatically by tools. Por exemplo, uma ferramenta de monitoramento pode notificar um administrador se um evento específico é rastreado por uma fonte específica.For example, a monitoring tool can notify an administrator if a specific event is traced by a specific source.
O TraceEvent método chama o ShouldTrace método do SourceSwitch objeto retornado pela Switch propriedade.The TraceEvent method calls the ShouldTrace method of the SourceSwitch object returned by the Switch property. Se ShouldTrace retorna true , TraceEvent chama o TraceEvent método correspondente de cada ouvinte.If ShouldTrace returns true, TraceEvent calls the corresponding TraceEvent method of each listener. Caso contrário, TraceEvent retorna sem chamar os métodos dos ouvintes.Otherwise, TraceEvent returns without calling the listeners' methods.
O conteúdo do rastreamento é específico do ouvinte.The trace content is listener specific. Se o método não for substituído pela implementação do ouvinte, a saída padrão será o nome da origem do rastreamento, sua identidade numérica e o tipo de evento.If the method is not overridden by the listener implementation, the default output is the name of the trace source, its numeric identity, and the event type. O conteúdo de rastreamento adicional depende do valor da Propriedade do ouvinte TraceOutputOptions .Additional trace content is dependent upon the listener's TraceOutputOptions property value.
Observação
O EventLogTraceListener objeto está limitado a um id valor máximo de 65.535.The EventLogTraceListener object is limited to a maximum id value of 65,535. Se o id valor especificado for maior que 65.535, o EventLogTraceListener usará 65.535.If the id value specified is greater than 65,535, the EventLogTraceListener uses 65,535.
Aplica-se a
TraceEvent(TraceEventType, Int32, String)
Grava uma mensagem de evento de rastreamento para os ouvintes de rastreamento na coleção Listeners usando o tipo de evento, o identificador de evento e a mensagem especificados.Writes a trace event message to the trace listeners in the Listeners collection using the specified event type, event identifier, and message.
public:
void TraceEvent(System::Diagnostics::TraceEventType eventType, int id, System::String ^ message);
[System.Diagnostics.Conditional("TRACE")]
public void TraceEvent (System.Diagnostics.TraceEventType eventType, int id, string? message);
[System.Diagnostics.Conditional("TRACE")]
public void TraceEvent (System.Diagnostics.TraceEventType eventType, int id, string message);
[<System.Diagnostics.Conditional("TRACE")>]
member this.TraceEvent : System.Diagnostics.TraceEventType * int * string -> unit
Public Sub TraceEvent (eventType As TraceEventType, id As Integer, message As String)
Parâmetros
- eventType
- TraceEventType
Um dos valores de enumeração que especifica o tipo de evento dos dados de rastreamento.One of the enumeration values that specifies the event type of the trace data.
- id
- Int32
Um identificador numérico do evento.A numeric identifier for the event.
- message
- String
A mensagem de rastreamento a ser gravada.The trace message to write.
- Atributos
Exceções
Foi feita uma tentativa de rastrear um evento durante a finalização.An attempt was made to trace an event during finalization.
Exemplos
O exemplo de código a seguir mostra o uso do TraceEvent(TraceEventType, Int32) método para passar um evento de rastreamento para os ouvintes.The following code example shows the use of the TraceEvent(TraceEventType, Int32) method to pass a trace event to the listeners. Este exemplo de código faz parte de um exemplo maior fornecido para a TraceSource classe.This code example is part of a larger example provided for the TraceSource class.
// Issue file not found message as a warning.
ts.TraceEvent(TraceEventType.Warning, 2, "File Test not found");
' Issue file not found message as a warning.
ts.TraceEvent(TraceEventType.Warning, 2, "File Test not found")
Comentários
O TraceEvent método destina-se a rastrear eventos que podem ser processados automaticamente por ferramentas.The TraceEvent method is intended to trace events that can be processed automatically by tools. Por exemplo, uma ferramenta de monitoramento pode notificar um administrador se um evento específico é rastreado por uma fonte específica.For example, a monitoring tool can notify an administrator if a specific event is traced by a specific source.
O TraceEvent método chama o ShouldTrace método do SourceSwitch objeto retornado pela Switch propriedade.The TraceEvent method calls the ShouldTrace method of the SourceSwitch object returned by the Switch property. Se ShouldTrace retorna true , TraceEvent chama o TraceEvent método correspondente de cada ouvinte.If ShouldTrace returns true, TraceEvent calls the corresponding TraceEvent method of each listener. Caso contrário, TraceEvent retorna sem chamar os métodos dos ouvintes.Otherwise, TraceEvent returns without calling the listeners' methods.
O conteúdo do rastreamento é específico do ouvinte.The trace content is listener specific. Se o método não for substituído pela implementação do ouvinte, a saída padrão será o nome da origem do rastreamento, sua identidade numérica, o tipo de evento e a mensagem.If the method is not overridden by the listener implementation, the default output is the name of the trace source, its numeric identity, the event type, and the message. O conteúdo de rastreamento adicional depende do valor da Propriedade do ouvinte TraceOutputOptions .Additional trace content is dependent upon the listener's TraceOutputOptions property value.
Observação
O EventLogTraceListener objeto está limitado a um id valor máximo de 65.535.The EventLogTraceListener object is limited to a maximum id value of 65,535. Se o id valor especificado for maior que 65.535, o EventLogTraceListener objeto usará 65.535.If the id value specified is greater than 65,535, the EventLogTraceListener object uses 65,535.
Aplica-se a
TraceEvent(TraceEventType, Int32, String, Object[])
Grava um evento de rastreamento para os ouvintes de rastreamento na coleção Listeners usando o tipo de evento, o identificador de evento, a matriz de argumentos e o formato especificados.Writes a trace event to the trace listeners in the Listeners collection using the specified event type, event identifier, and argument array and format.
public:
void TraceEvent(System::Diagnostics::TraceEventType eventType, int id, System::String ^ format, ... cli::array <System::Object ^> ^ args);
[System.Diagnostics.Conditional("TRACE")]
public void TraceEvent (System.Diagnostics.TraceEventType eventType, int id, string format, params object?[]? args);
[System.Diagnostics.Conditional("TRACE")]
public void TraceEvent (System.Diagnostics.TraceEventType eventType, int id, string format, params object[] args);
[<System.Diagnostics.Conditional("TRACE")>]
member this.TraceEvent : System.Diagnostics.TraceEventType * int * string * obj[] -> unit
Public Sub TraceEvent (eventType As TraceEventType, id As Integer, format As String, ParamArray args As Object())
Parâmetros
- eventType
- TraceEventType
Um dos valores de enumeração que especifica o tipo de evento dos dados de rastreamento.One of the enumeration values that specifies the event type of the trace data.
- id
- Int32
Um identificador numérico do evento.A numeric identifier for the event.
- format
- String
Uma cadeia de caracteres de formato de composição que contém texto intercalado com zero ou mais itens de formato correspondentes a objetos na matriz args.A composite format string that contains text intermixed with zero or more format items, which correspond to objects in the args array.
- args
- Object[]
Uma matriz object que contém zero ou mais objetos a serem formatados.An object array containing zero or more objects to format.
- Atributos
Exceções
format é null.format is null.
format é inválido.format is invalid.
- ou --or- O número que indica um argumento para o formato é menor que zero ou maior ou igual ao número de objetos especificados a serem formatados.The number that indicates an argument to format is less than zero, or greater than or equal to the number of specified objects to format.
Foi feita uma tentativa de rastrear um evento durante a finalização.An attempt was made to trace an event during finalization.
Exemplos
O exemplo de código a seguir mostra o uso do TraceEvent(TraceEventType, Int32) método para passar um evento de rastreamento para os ouvintes.The following code example shows the use of the TraceEvent(TraceEventType, Int32) method to pass a trace event to the listeners. Este exemplo de código faz parte de um exemplo maior fornecido para a TraceSource classe.This code example is part of a larger example provided for the TraceSource class.
// Issue file not found message as a verbose event using a formatted string.
ts.TraceEvent(TraceEventType.Verbose, 3, "File {0} not found.", "test");
' Issue file not found message as a verbose event using a formatted string.
ts.TraceEvent(TraceEventType.Verbose, 3, "File {0} not found.", "test")
Comentários
Para obter mais informações sobre o format parâmetro, consulte formatação composta.For more information about the format parameter, see Composite Formatting.
O TraceEvent método destina-se a rastrear eventos que podem ser processados automaticamente por ferramentas.The TraceEvent method is intended to trace events that can be processed automatically by tools. Por exemplo, uma ferramenta de monitoramento pode notificar um administrador se um evento específico é rastreado por uma fonte específica.For example, a monitoring tool can notify an administrator if a specific event is traced by a specific source.
O TraceEvent método chama o ShouldTrace método do SourceSwitch objeto retornado pela Switch propriedade.The TraceEvent method calls the ShouldTrace method of the SourceSwitch object returned by the Switch property. Se ShouldTrace retorna true , TraceEvent chama o TraceEvent método correspondente de cada ouvinte.If ShouldTrace returns true, TraceEvent calls the corresponding TraceEvent method of each listener. Caso contrário, TraceEvent retorna sem chamar os métodos dos ouvintes.Otherwise, TraceEvent returns without calling the listeners' methods.
O conteúdo do rastreamento é específico do ouvinte.The trace content is listener specific. O TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[]) método padrão grava o nome de origem, o tipo de evento e a identidade numérica no cabeçalho de rastreamento, em seguida, chama o String.Format(IFormatProvider, String, Object[]) método, passando a format cadeia de caracteres e a args matriz e usando a CultureInfo.InvariantCulture propriedade para formatar a cadeia de caracteres como a saída da mensagem.The default TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[]) method writes the source name, event type, and numeric identity in the trace header, then calls the String.Format(IFormatProvider, String, Object[]) method, passing the format string and args array and using the CultureInfo.InvariantCulture property to format the string as the message output.
Observação
O EventLogTraceListener objeto está limitado a um id valor máximo de 65.535.The EventLogTraceListener object is limited to a maximum id value of 65,535. Se o id valor especificado for maior que 65.535, o EventLogTraceListener objeto usará 65.535.If the id value specified is greater than 65,535, the EventLogTraceListener object uses 65,535.