Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original
Este tópico ainda não foi avaliado como - Avalie este tópico

EventInstance Classe

Representa informações idioma neutro para uma entrada do log de eventos.

Namespace:  System.Diagnostics
Assembly:  System (em System. dll)
public class EventInstance

Use EventInstance to write an event log entry with a resource identifier rather than a string value.To write an event log entry, initialize the InstanceId property and pass the instance to the WriteEvent method.The Viewer Event uses the identificador instância to localizar and exibir The correspondente Cadeia de Caracteres from the arquivo de recurso localized based on atual linguagem Settings.You Must registrar the with the Before You Gravar Events Using Identifiers .

When writing events, you can set the EntryType property to specify the icon that the Event Viewer displays for the entry.You can also specify a CategoryId property to specify the category that the Event Viewer displays for the entry.

The categoria to uses the Viewer Event Filtro Events Written by an fonte de evento.Can the Viewer Event exibir The categoria as a valor Numeric, or it can use the categoria as a identificador recurso to exibir a categoria localized Cadeia de Caracteres.

To display localized category strings in the Event Viewer, you must use an event source configured with a category resource file, and set the CategoryId to a resource identifier in the category resource file.If the event source does not have a configured category resource file, or the specified CategoryId does not index a string in the category resource file, and then the Event Viewer displays the numeric category value for that entry.Configure the category resource file, along with the number of category strings in the resource file, using the EventLogInstaller or the EventSourceCreationData class.

You must register a source for an event log before using EventInstance to write an event with the WriteEvent method.The origem must be configured for Writing to the log entries localized and the origem must define no mínimo a arquivo recurso mensagem.

Criar o novo evento Origem durante a instalação do seu aplicativo.Isso permite que momento para o sistema operacional atualizar sua lista de fontes de eventos registrados e suas configurações.If the sistema operacional not has refreshed its lista of Sources evento, and you attempt to Gravar an evento with the New origem, the Gravar operação will Fail.You can configure a new source using an EventLogInstaller, or using the CreateEventSource method.You Must Have administrativo Rights on the computador to create a Novo Evento origem.

For details about defining event messages and building event log resource files, see the "Message Compiler" topic in the Platform SDK documentation at http://msdn.microsoft.com.

Windows 98, Windows Millennium Edition Platform Note:

Logs de eventos não são no Windows 98/Windows Millennium Edition (Me) oferece suporte para.

The following code example writes an informational event entry, and then reuses the EventInstance to write an entry for a warning event to an existing event log.O texto da mensagem de evento é especificado usando um identificador de recurso em um arquivo de recurso de mensagens.The exemplo de código assumes that the correspondente recurso mensagem Arquivo has been Registered for the origem.


// Ensure that the source has already been registered using
// EventLogInstaller or EventLog.CreateEventSource.

string sourceName = "SampleApplicationSource";
if(EventLog.SourceExists(sourceName))
{
    // Define an informational event with no category.
    // The message identifier corresponds to the message text in the
    // message resource file defined for the source.
    EventInstance myEvent = new EventInstance(UpdateCycleCompleteMsgId, 0);

    // Write the event to the event log using the registered source.
    EventLog.WriteEvent(sourceName, myEvent);

    // Reuse the event data instance for another event entry.
    // Set the entry category and message identifiers for
    // the appropriate resource identifiers in the resource files
    // for the registered source.  Set the event type to Warning.

    myEvent.CategoryId = RefreshCategoryMsgId;
    myEvent.EntryType = EventLogEntryType.Warning;
    myEvent.InstanceId = ServerConnectionDownMsgId;

    // Write the event to the event log using the registered source.
    // Insert the machine name into the event message text.
    EventLog.WriteEvent(sourceName, myEvent, Environment.MachineName);
}
else 
{
    Console.WriteLine("Warning - event source {0} not registered", 
        sourceName);
}



The code example uses the following message text file, built into the resource library EventLogMsgs.dll.A message text file is the source from which the message resource file is created.The arquivo de texto mensagem Defines the Identifiers recurso and Text for the categoria, mensagem evento, and inserção parâmetro Cadeia de caracteres.

; // EventLogMsgs.mc
; // ********************************************************

; // Use the following commands to build this file:

; //   mc -s EventLogMsgs.mc
; //   rc EventLogMsgs.rc
; //   link /DLL /SUBSYSTEM:WINDOWS /NOENTRY /MACHINE:x86 EventLogMsgs.Res 
; // ********************************************************

; // - Event categories -
; // Categories must be numbered consecutively starting at 1.
; // ********************************************************

MessageId=0x1
Severity=Success
SymbolicName=INSTALL_CATEGORY
Language=English
Installation
.

MessageId=0x2
Severity=Success
SymbolicName=QUERY_CATEGORY
Language=English
Database Query
.

MessageId=0x3
Severity=Success
SymbolicName=REFRESH_CATEGORY
Language=English
Data Refresh
.

; // - Event messages -
; // *********************************

MessageId = 1000
Severity = Success
Facility = Application
SymbolicName = AUDIT_SUCCESS_MESSAGE_ID_1000
Language=English
My application message text, in English, for message id 1000, called from %1.
.

MessageId = 1001
Severity = Warning
Facility = Application
SymbolicName = AUDIT_FAILED_MESSAGE_ID_1001
Language=English
My application message text, in English, for message id 1001, called from %1.
.


MessageId = 1002
Severity = Success
Facility = Application
SymbolicName = GENERIC_INFO_MESSAGE_ID_1002
Language=English
My generic information message in English, for message id 1002.
.


MessageId = 1003
Severity = Warning
Facility = Application
SymbolicName = GENERIC_WARNING_MESSAGE_ID_1003
Language=English
My generic warning message in English, for message id 1003, called from %1.
.


MessageId = 1004
Severity = Success
Facility = Application
SymbolicName = UPDATE_CYCLE_COMPLETE_MESSAGE_ID_1004
Language=English
The update cycle is complete for %%5002.
.


MessageId = 1005
Severity = Warning
Facility = Application
SymbolicName = SERVER_CONNECTION_DOWN_MESSAGE_ID_1005
Language=English
The refresh operation did not complete because the connection to server %1 could not be established.
.


; // - Event log display name -
; // ********************************************************


MessageId = 5001
Severity = Success
Facility = Application
SymbolicName = EVENT_LOG_DISPLAY_NAME_MSGID
Language=English
Sample Event Log
.



; // - Event message parameters -
; //   Language independent insertion strings
; // ********************************************************


MessageId = 5002
Severity = Success
Facility = Application
SymbolicName = EVENT_LOG_SERVICE_NAME_MSGID
Language=English
SVC_UPDATE.EXE
.
System.Object
  System.Diagnostics.EventInstance
Quaisquer membros públicos estático (compartilhados na Visual Basic) desse tipo são Thread seguro. Não há garantia de que qualquer membro de instância seja isento de segmentos.
Isso foi útil para você?
(1500 caracteres restantes)

Contribuições da comunidade

ADICIONAR
© 2013 Microsoft. Todos os direitos reservados.