EventLog Construtores
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Inicializa uma nova instância da classe EventLog.
Sobrecargas
| Nome | Description |
|---|---|
| EventLog() |
Inicializa uma nova instância da classe EventLog. Não associa a instância a nenhum log. |
| EventLog(String) |
Inicializa uma nova instância da classe EventLog. Associa a instância a um log no computador local. |
| EventLog(String, String) |
Inicializa uma nova instância da classe EventLog. Associa a instância a um log no computador especificado. |
| EventLog(String, String, String) |
Inicializa uma nova instância da classe EventLog. Associa a instância a um log no computador especificado e cria ou atribui a origem especificada ao EventLog. |
EventLog()
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
Inicializa uma nova instância da classe EventLog. Não associa a instância a nenhum log.
public:
EventLog();
public EventLog();
Public Sub New ()
Exemplos
O exemplo a seguir cria a origem MySource se ela ainda não existir e grava uma entrada no log de eventos MyNewLog.
using System;
using System.Diagnostics;
using System.Threading;
class MySample{
public static void Main(){
// Create the source, if it does not already exist.
if(!EventLog.SourceExists("MySource"))
{
//An event log source should not be created and immediately used.
//There is a latency time to enable the source, it should be created
//prior to executing the application that uses the source.
//Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog");
Console.WriteLine("CreatedEventSource");
Console.WriteLine("Exiting, execute the application a second time to use the source.");
// The source is created. Exit the application to allow it to be registered.
return;
}
// Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "MySource";
// Write an informational entry to the event log.
myLog.WriteEntry("Writing to event log.");
}
}
Option Explicit
Option Strict
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
If Not EventLog.SourceExists("MySource") Then
' Create the source, if it does not already exist.
' An event log source should not be created and immediately used.
' There is a latency time to enable the source, it should be created
' prior to executing the application that uses the source.
' Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog")
Console.WriteLine("CreatingEventSource")
'The source is created. Exit the application to allow it to be registered.
Return
End If
' Create an EventLog instance and assign its source.
Dim myLog As New EventLog()
myLog.Source = "MySource"
' Write an informational entry to the event log.
myLog.WriteEntry("Writing to event log.")
End Sub
End Class
Comentários
Antes de chamar WriteEntry, especifique a Source propriedade da EventLog instância. Se você estiver lendo Entries apenas do log, você poderá, como alternativa, especificar apenas as propriedades e MachineName as Log propriedades.
Observação
Se você não especificar um MachineName, o computador local (".") será assumido.
A tabela a seguir mostra valores de propriedade iniciais para uma instância de EventLog.
| Propriedade | Valor Inicial |
|---|---|
| Source | Uma cadeia de caracteres vazia (""). |
| Log | Uma cadeia de caracteres vazia (""). |
| MachineName | O computador local ("."). |
Confira também
Aplica-se a
EventLog(String)
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
Inicializa uma nova instância da classe EventLog. Associa a instância a um log no computador local.
public:
EventLog(System::String ^ logName);
public EventLog(string logName);
new System.Diagnostics.EventLog : string -> System.Diagnostics.EventLog
Public Sub New (logName As String)
Parâmetros
- logName
- String
O nome do log no computador local.
Exceções
O nome do log é null.
O nome do log é inválido.
Exemplos
O exemplo a seguir lê entradas no log de eventos, "myNewLog", no computador local.
using System;
using System.Diagnostics;
using System.Threading;
class MySample
{
public static void Main()
{
// Create the source, if it does not already exist.
if (!EventLog.SourceExists("MySource"))
{
//An event log source should not be created and immediately used.
//There is a latency time to enable the source, it should be created
//prior to executing the application that uses the source.
//Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog");
Console.WriteLine("CreatedEventSource");
Console.WriteLine("Exiting, execute the application a second time to use the source.");
// The source is created. Exit the application to allow it to be registered.
return;
}
// Create an EventLog instance and assign its log name.
EventLog myLog = new EventLog("myNewLog");
// Read the event log entries.
foreach (EventLogEntry entry in myLog.Entries)
{
Console.WriteLine("\tEntry: " + entry.Message);
}
}
}
Option Explicit
Option Strict
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
If Not EventLog.SourceExists("MySource") Then
' Create the source, if it does not already exist.
' An event log source should not be created and immediately used.
' There is a latency time to enable the source, it should be created
' prior to executing the application that uses the source.
' Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog")
Console.WriteLine("CreatingEventSource")
'The source is created. Exit the application to allow it to be registered.
Return
End If
Dim myLog As New EventLog("myNewLog")
' Read the event log entries.
Dim entry As EventLogEntry
For Each entry In myLog.Entries
Console.WriteLine((ControlChars.Tab & "Entry: " & entry.Message))
Next entry
End Sub
End Class
Comentários
Essa sobrecarga define a Log propriedade como o logName parâmetro. Antes de chamar WriteEntry, especifique a Source propriedade da EventLog instância. Se você estiver lendo Entries apenas do log, você poderá, como alternativa, especificar apenas as propriedades e MachineName as Log propriedades.
Observação
Se você não especificar um MachineName, o computador local (".") será assumido. Essa sobrecarga do construtor especifica a Log propriedade, mas você pode alterá-la antes de ler a Entries propriedade.
Se a origem especificada na Source propriedade for exclusiva de outras fontes no computador, uma chamada subsequente para WriteEntry criar um log com o nome especificado, se ela ainda não existir.
A tabela a seguir mostra valores de propriedade iniciais para uma instância de EventLog.
| Propriedade | Valor Inicial |
|---|---|
| Source | Uma cadeia de caracteres vazia (""). |
| Log | O logName parâmetro. |
| MachineName | O computador local ("."). |
Confira também
Aplica-se a
EventLog(String, String)
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
Inicializa uma nova instância da classe EventLog. Associa a instância a um log no computador especificado.
public:
EventLog(System::String ^ logName, System::String ^ machineName);
public EventLog(string logName, string machineName);
new System.Diagnostics.EventLog : string * string -> System.Diagnostics.EventLog
Public Sub New (logName As String, machineName As String)
Parâmetros
- logName
- String
O nome do log no computador especificado.
- machineName
- String
O computador no qual o log existe.
Exceções
O nome do log é null.
Exemplos
O exemplo a seguir lê entradas no log de eventos, "myNewLog", no computador "myServer".
using System;
using System.Diagnostics;
using System.Threading;
class MySample1
{
public static void Main()
{
// Create the source, if it does not already exist.
if (!EventLog.SourceExists("MySource"))
{
//An event log source should not be created and immediately used.
//There is a latency time to enable the source, it should be created
//prior to executing the application that uses the source.
//Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog", "myServer");
Console.WriteLine("CreatedEventSource");
Console.WriteLine("Exiting, execute the application a second time to use the source.");
// The source is created. Exit the application to allow it to be registered.
return;
}
// Create an EventLog instance and assign its log name.
EventLog myLog = new EventLog("myNewLog", "myServer");
// Read the event log entries.
foreach (EventLogEntry entry in myLog.Entries)
{
Console.WriteLine("\tEntry: " + entry.Message);
}
}
}
Option Explicit
Option Strict
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
If Not EventLog.SourceExists("MySource") Then
' Create the source, if it does not already exist.
' An event log source should not be created and immediately used.
' There is a latency time to enable the source, it should be created
' prior to executing the application that uses the source.
' Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog", "myServer")
Console.WriteLine("CreatingEventSource")
'The source is created. Exit the application to allow it to be registered.
Return
End If
' Create an EventLog instance and assign its log name.
Dim myLog As New EventLog("myNewLog", "myServer")
' Read the event log entries.
Dim entry As EventLogEntry
For Each entry In myLog.Entries
Console.WriteLine((ControlChars.Tab & "Entry: " & entry.Message))
Next entry
End Sub
End Class
Comentários
Essa sobrecarga define a Log propriedade como o logName parâmetro e a MachineName propriedade para o machineName parâmetro. Antes de chamar WriteEntry, especifique a Source propriedade do EventLog. Se você estiver lendo Entries apenas do log, você poderá, como alternativa, especificar apenas as propriedades e MachineName as Log propriedades.
Observação
Essa sobrecarga do construtor especifica as propriedades e MachineName as Log propriedades, mas você pode alterar qualquer um antes de ler a Entries propriedade.
A tabela a seguir mostra valores de propriedade iniciais para uma instância de EventLog.
| Propriedade | Valor Inicial |
|---|---|
| Source | Uma cadeia de caracteres vazia (""). |
| Log | O logName parâmetro. |
| MachineName | O machineName parâmetro. |
Confira também
Aplica-se a
EventLog(String, String, String)
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
- Origem:
- EventLog.cs
public:
EventLog(System::String ^ logName, System::String ^ machineName, System::String ^ source);
public EventLog(string logName, string machineName, string source);
new System.Diagnostics.EventLog : string * string * string -> System.Diagnostics.EventLog
Public Sub New (logName As String, machineName As String, source As String)
Parâmetros
- logName
- String
O nome do log no computador especificado.
- machineName
- String
O computador no qual o log existe.
- source
- String
A origem das entradas de log de eventos.
Exceções
O nome do log é null.
Exemplos
O exemplo a seguir grava uma entrada em um log de eventos, "MyNewLog", no computador local, usando a origem "MySource".
using System;
using System.Diagnostics;
using System.Threading;
class MySample2
{
public static void Main()
{
// Create the source, if it does not already exist.
if (!EventLog.SourceExists("MySource"))
{
//An event log source should not be created and immediately used.
//There is a latency time to enable the source, it should be created
//prior to executing the application that uses the source.
//Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog");
Console.WriteLine("CreatedEventSource");
Console.WriteLine("Exiting, execute the application a second time to use the source.");
// The source is created. Exit the application to allow it to be registered.
return;
}
// Create an EventLog instance and assign its source.
EventLog myLog = new EventLog("myNewLog", ".", "MySource");
// Write an entry to the log.
myLog.WriteEntry("Writing to event log on " + myLog.MachineName);
}
}
Option Strict
Option Explicit
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
If Not EventLog.SourceExists("MySource") Then
' Create the source, if it does not already exist.
' An event log source should not be created and immediately used.
' There is a latency time to enable the source, it should be created
' prior to executing the application that uses the source.
' Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog")
Console.WriteLine("CreatingEventSource")
'The source is created. Exit the application to allow it to be registered.
Return
End If
' Create an EventLog instance and assign its source.
Dim myLog As New EventLog("myNewLog", ".", "MySource")
' Write an entry to the log.
myLog.WriteEntry(("Writing to event log on " & myLog.MachineName))
End Sub
End Class
Comentários
Esse construtor define a Log propriedade como o logName parâmetro, a MachineName propriedade para o machineName parâmetro e a Source propriedade para o source parâmetro. A Source propriedade é necessária ao gravar em um log de eventos. No entanto, se você estiver lendo apenas de um log de eventos, somente as propriedades e MachineName as Log propriedades serão necessárias (desde que o log de eventos no servidor tenha uma origem já associada a ele). Se você estiver lendo apenas do log de eventos, outra sobrecarga do construtor poderá ser suficiente.
A tabela a seguir mostra valores de propriedade iniciais para uma instância de EventLog.
| Propriedade | Valor Inicial |
|---|---|
| Source | O source parâmetro. |
| Log | O logName parâmetro. |
| MachineName | O machineName parâmetro. |