EventLog Konstruktorer
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Initierar en ny instans av EventLog klassen.
Överlagringar
| Name | Description |
|---|---|
| EventLog() |
Initierar en ny instans av EventLog klassen. Associerar inte instansen med någon logg. |
| EventLog(String) |
Initierar en ny instans av EventLog klassen. Associerar instansen med en logg på den lokala datorn. |
| EventLog(String, String) |
Initierar en ny instans av EventLog klassen. Associerar instansen med en logg på den angivna datorn. |
| EventLog(String, String, String) |
Initierar en ny instans av EventLog klassen. Associerar instansen med en logg på den angivna datorn och skapar eller tilldelar den angivna källan till EventLog. |
EventLog()
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
Initierar en ny instans av EventLog klassen. Associerar inte instansen med någon logg.
public:
EventLog();
public EventLog();
Public Sub New ()
Exempel
I följande exempel skapas källan MySource om den inte redan finns och skriver en post till händelseloggen 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
Kommentarer
Innan du anropar WriteEntryanger du instansens SourceEventLog egenskap. Om du bara läser Entries från loggen kan du också bara Log ange egenskaperna och MachineName .
Note
Om du inte anger en MachineNameantas den lokala datorn (".").
I följande tabell visas inledande egenskapsvärden för en instans av EventLog.
| Fastighet | Initialt värde |
|---|---|
| Source | En tom sträng (""). |
| Log | En tom sträng (""). |
| MachineName | Den lokala datorn ("."). |
Se även
Gäller för
EventLog(String)
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
Initierar en ny instans av EventLog klassen. Associerar instansen med en logg på den lokala datorn.
public:
EventLog(System::String ^ logName);
public EventLog(string logName);
new System.Diagnostics.EventLog : string -> System.Diagnostics.EventLog
Public Sub New (logName As String)
Parametrar
- logName
- String
Namnet på loggen på den lokala datorn.
Undantag
Loggnamnet är null.
Loggnamnet är ogiltigt.
Exempel
I följande exempel läss poster i händelseloggen"myNewLog" på den lokala datorn.
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
Kommentarer
Den här överlagringen Log anger egenskapen till parametern logName . Innan du anropar WriteEntryanger du instansens SourceEventLog egenskap. Om du bara läser Entries från loggen kan du också bara Log ange egenskaperna och MachineName .
Note
Om du inte anger en MachineNameantas den lokala datorn ("."). Den här överlagringen av konstruktorn anger Log egenskapen, men du kan ändra den innan du läser egenskapen Entries .
Om källan som du anger i Source egenskapen är unik från andra källor på datorn, skapar ett efterföljande anrop till WriteEntry en logg med det angivna namnet, om den inte redan finns.
I följande tabell visas inledande egenskapsvärden för en instans av EventLog.
| Fastighet | Initialt värde |
|---|---|
| Source | En tom sträng (""). |
| Log | Parametern logName . |
| MachineName | Den lokala datorn ("."). |
Se även
Gäller för
EventLog(String, String)
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
Initierar en ny instans av EventLog klassen. Associerar instansen med en logg på den angivna datorn.
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)
Parametrar
- logName
- String
Namnet på loggen på den angivna datorn.
- machineName
- String
Datorn där loggen finns.
Undantag
Loggnamnet är null.
Exempel
I följande exempel läss poster i händelseloggen"myNewLog" på datorn "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
Kommentarer
Den här överlagringen Log anger egenskapen till parametern logName och egenskapen MachineName till parametern machineName . Innan du anropar WriteEntryanger du Source egenskapen för EventLog. Om du bara läser Entries från loggen kan du också bara Log ange egenskaperna och MachineName .
Note
Den här överbelastningen av konstruktorn anger Log egenskaperna och MachineName , men du kan ändra antingen innan du läser Entries egenskapen.
I följande tabell visas inledande egenskapsvärden för en instans av EventLog.
| Fastighet | Initialt värde |
|---|---|
| Source | En tom sträng (""). |
| Log | Parametern logName . |
| MachineName | Parametern machineName . |
Se även
Gäller för
EventLog(String, String, String)
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- EventLog.cs
- Källa:
- 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)
Parametrar
- logName
- String
Namnet på loggen på den angivna datorn.
- machineName
- String
Datorn där loggen finns.
- source
- String
Källan till händelseloggposter.
Undantag
Loggnamnet är null.
Exempel
I följande exempel skrivs en post till en händelselogg, "MyNewLog", på den lokala datorn med källan "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
Kommentarer
Den här konstruktorn anger Log egenskapen till parametern logName , MachineName egenskapen till parametern machineName och Source egenskapen till parametern source . Egenskapen Source krävs när du skriver till en händelselogg. Men om du bara läser från en händelselogg krävs endast Log egenskaperna och MachineName (så länge händelseloggen på servern redan har en källa associerad med den). Om du bara läser från händelseloggen kan en annan överbelastning av konstruktorn räcka.
I följande tabell visas inledande egenskapsvärden för en instans av EventLog.
| Fastighet | Initialt värde |
|---|---|
| Source | Parametern source . |
| Log | Parametern logName . |
| MachineName | Parametern machineName . |