EntryWrittenEventArgs 类
为 EntryWritten 事件提供数据。
**命名空间:**System.Diagnostics
**程序集:**System(在 system.dll 中)
语法
声明
Public Class EntryWrittenEventArgs
Inherits EventArgs
用法
Dim instance As EntryWrittenEventArgs
public class EntryWrittenEventArgs : EventArgs
public ref class EntryWrittenEventArgs : public EventArgs
public class EntryWrittenEventArgs extends EventArgs
public class EntryWrittenEventArgs extends EventArgs
示例
下面的示例演示了 EntryWrittenEventArgs 构造函数。它创建一个自定义的 EventLog 对象并将一项写入其中。然后它使用此自定义 EventLog 中的第一项创建一个 EntryWrittenEventArgs 对象。此对象用于通知消息。
Imports System
Imports System.Diagnostics
Class MySample
Public Shared Sub Main()
Try
Dim myNewLog As New EventLog()
myNewLog.Log = "MyNewLog"
myNewLog.Source = "MySource"
' Create the source if it does not exist already.
If Not EventLog.SourceExists("MySource") Then
EventLog.CreateEventSource("MySource", "MyNewLog")
Console.WriteLine("CreatingEventSource")
End If
' Write an entry to the EventLog.
myNewLog.WriteEntry("The Latest entry in the Event Log")
Dim myEntryEventArgs As EntryWrittenEventArgs = _
New EntryWrittenEventArgs()
MyOnEntry(myNewLog, myEntryEventArgs)
Catch e As Exception
Console.WriteLine("Exception Raised" + e.Message)
End Try
End Sub 'Main
Protected Shared Sub MyOnEntry(ByVal source As Object, _
ByVal e As EntryWrittenEventArgs)
If e.Entry Is Nothing Then
Console.WriteLine("A new entry is written in MyNewLog.")
End If
End Sub 'MyOnEntry
End Class 'MySample
using System;
using System.Diagnostics;
class MySample
{
public static void Main()
{
try
{
EventLog myNewLog = new EventLog();
myNewLog.Log = "MyNewLog";
myNewLog.Source="MySource";
// Create the source if it does not exist already.
if(!EventLog.SourceExists("MySource"))
{
EventLog.CreateEventSource("MySource", "MyNewLog");
Console.WriteLine("CreatingEventSource");
}
// Write an entry to the EventLog.
myNewLog.WriteEntry("The Latest entry in the Event Log");
int myEntries = myNewLog.Entries.Count;
EventLogEntry entry =myNewLog.Entries[myEntries-1];
EntryWrittenEventArgs myEntryEventArgs=
new EntryWrittenEventArgs();
MyOnEntry(myNewLog,myEntryEventArgs);
}
catch(Exception e)
{
Console.WriteLine("Exception Raised" +e.Message);
}
}
protected static void MyOnEntry(Object source, EntryWrittenEventArgs e)
{
if(e.Entry == null)
Console.WriteLine("A new entry is written in MyNewLog.");
}
}
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
void MyOnEntry( Object^ source, EntryWrittenEventArgs^ e )
{
if ( !e->Entry )
Console::WriteLine( "A new entry is written in MyNewLog." );
}
int main()
{
try
{
EventLog^ myNewLog = gcnew EventLog;
myNewLog->Log = "MyNewLog";
myNewLog->Source = "MySource";
// Create the source if it does not exist already.
if ( !EventLog::SourceExists( "MySource" ) )
{
EventLog::CreateEventSource( "MySource", "MyNewLog" );
Console::WriteLine( "CreatingEventSource" );
}
// Write an entry to the EventLog.
myNewLog->WriteEntry( "The Latest entry in the Event Log" );
int myEntries = myNewLog->Entries->Count;
EventLogEntry^ entry = myNewLog->Entries[ myEntries - 1 ];
EntryWrittenEventArgs^ myEntryEventArgs = gcnew EntryWrittenEventArgs;
MyOnEntry( myNewLog, myEntryEventArgs );
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception Raised{0}", e->Message );
}
}
import System.*;
import System.Diagnostics.*;
class MySample
{
public static void main(String[] args)
{
try {
EventLog myNewLog = new EventLog();
myNewLog.set_Log("MyNewLog");
myNewLog.set_Source("MySource");
// Create the source if it does not exist already.
if (!(EventLog.SourceExists("MySource"))) {
EventLog.CreateEventSource("MySource", "MyNewLog");
Console.WriteLine("CreatingEventSource");
}
// Write an entry to the EventLog.
myNewLog.WriteEntry("The Latest entry in the Event Log");
int myEntries = myNewLog.get_Entries().get_Count();
EventLogEntry entry = myNewLog.get_Entries().
get_Item((myEntries - 1));
EntryWrittenEventArgs myEntryEventArgs = new EntryWrittenEventArgs();
MyOnEntry(myNewLog, myEntryEventArgs);
}
catch (System.Exception e) {
Console.WriteLine("Exception Raised" + e.get_Message());
}
} //main
private static void MyOnEntry(Object source, EntryWrittenEventArgs e)
{
if (e.get_Entry() == null) {
Console.WriteLine("A new entry is written in MyNewLog.");
}
} //MyOnEntry
} //MySample
继承层次结构
System.Object
System.EventArgs
System.Diagnostics.EntryWrittenEventArgs
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
EntryWrittenEventArgs 成员
System.Diagnostics 命名空间
EntryWritten
EntryWrittenEventHandler
EventLog