EventProvider.WriteEvent 方法
定义
写入某个事件。Writes an event.
重载
| WriteEvent(EventDescriptor, Object[]) |
写入某个事件。Writes an event. 以对象数组形式指定事件数据。The event data is specified as an array of objects. |
| WriteEvent(EventDescriptor, String) |
写入某个事件。Writes an event. 以字符串形式指定事件数据。The event data is specified as a string. |
| WriteEvent(EventDescriptor, Int32, IntPtr) |
写入某个事件。Writes an event. 以内存块形式指定事件数据。The event data is specified as a block of memory. |
注解
如果使用清单来定义事件,请使用这些方法。Use these methods if you use a manifest to define your events.
WriteEvent(EventDescriptor, Object[])
写入某个事件。Writes an event. 以对象数组形式指定事件数据。The event data is specified as an array of objects.
public:
bool WriteEvent(System::Diagnostics::Eventing::EventDescriptor % eventDescriptor, ... cli::array <System::Object ^> ^ eventPayload);
[System.Security.SecurityCritical]
public bool WriteEvent (ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, params object[] eventPayload);
public bool WriteEvent (ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, params object[] eventPayload);
[<System.Security.SecurityCritical>]
member this.WriteEvent : EventDescriptor * obj[] -> bool
member this.WriteEvent : EventDescriptor * obj[] -> bool
Public Function WriteEvent (ByRef eventDescriptor As EventDescriptor, ParamArray eventPayload As Object()) As Boolean
参数
- eventDescriptor
- EventDescriptor
用来标识要写入的事件的 EventDescriptor 实例。An instance of EventDescriptor that identifies the event to write.
- eventPayload
- Object[]
包含要写入的事件数据的对象数组。An array of objects that contain the event data to write. 该对象必须采用清单中所指定的顺序。The object must be in the order specified in the manifest. 该数组限制为 32 个对象,其中只有八个对象可以是字符串。The array is limited to 32 objects, of which only eight may be strings. 事件数据的最大大小限制为 64 KB 减去事件头大小所得的值。The maximum data size for the event is limited to 64 KB minus the size of the event headers. 如果会话的缓冲区较小,而且会话中包括事件的扩展数据项,则该事件会较小。The event size is less if the session's buffer size is less and the session includes extended data items with the event.
此参数可以为 null。This parameter can be null.
返回
如果写入此事件,则为 true;否则为 false。Is true if the event is written; otherwise, false. 如果为 false,则调用 GetLastWriteEventError() 方法来确定失败的原因。If false, call the GetLastWriteEventError() method to determine the cause of the failure.
- 属性
例外
eventPayload 参数包含的对象或字符串太多。The eventPayload parameter contains too many objects or strings.
示例
private static Guid providerId = new Guid("{FB33FDA8-45FB-4df0-8A55-EEB4BA88E7E7}");
enum Keyword
{
Read = 0x1,
Write = 0x2,
Local = 0x4,
Remote = 0x8
}
enum Level
{
Critical = 1,
Error,
Warning,
Information,
Verbose
}
EventProvider provider = new EventProvider(providerId);
EventDescriptor readEvent;
string path = @"<PATHGOESHERE>";
UInt64 bytesRead = <ASSIGNVALUE>;
if (provider.IsEnabled(Level.Information, (long)Keyword.Read))
{
unchecked
{
readEvent = new EventDescriptor(0x1, 0x0, 0x10, 0x4, 0x0, 0x0, (long)0x8000000000000005);
}
if (!provider.WriteEvent(ref readEvent, new object[] { path, bytesRead }))
Console.WriteLine(EventProvider.GetLastWriteEventError());
}
provider.Close();
注解
如果调用 SetActivityId 方法为事件指定活动标识符,则此方法将从线程上下文中检索标识符,并将其包括在事件中。If you call the SetActivityId method to specify an activity identifier for the event, this method retrieves the identifier from the thread context and includes it with the event.
如果对象类型不受支持,则方法会在负载中写入对象的方法的值 Object.ToString 。If the object type is not supported, the method writes the value of the object's Object.ToString method in the payload. 有关支持的对象类型的列表,请参阅类的 "备注" EventProvider 。For a list of supported object types, see the Remarks for the EventProvider class.
适用于
WriteEvent(EventDescriptor, String)
写入某个事件。Writes an event. 以字符串形式指定事件数据。The event data is specified as a string.
public:
bool WriteEvent(System::Diagnostics::Eventing::EventDescriptor % eventDescriptor, System::String ^ data);
[System.Security.SecurityCritical]
public bool WriteEvent (ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, string data);
[<System.Security.SecurityCritical>]
member this.WriteEvent : EventDescriptor * string -> bool
Public Function WriteEvent (ByRef eventDescriptor As EventDescriptor, data As String) As Boolean
参数
- eventDescriptor
- EventDescriptor
用来标识要写入的事件的 EventDescriptor 实例。An instance of EventDescriptor that identifies the event to write.
- data
- String
要作为事件数据写入的字符串。The string to write as the event data.
返回
如果写入此事件,则为 true;否则为 false。Is true if the event is written; otherwise, false. 如果为 false,则调用 GetLastWriteEventError() 方法来确定失败的原因。If false, call the GetLastWriteEventError() method to determine the cause of the failure.
- 属性
例外
如果 data 为 null。If data is null.
示例
private static Guid providerId = new Guid("{FB33FDA8-45FB-4df0-8A55-EEB4BA88E7E7}");
EventProvider provider = new EventProvider(providerId);
EventDescriptor writeEvent;
if (provider.IsEnabled())
{
unchecked
{
writeEvent = new EventDescriptor(0x2, 0x0, 0x10, 0x3, 0x0, 0x0, (long)0x8000000000000006);
}
if (!provider.WriteEvent(ref writeEvent, "Write event."))
Console.WriteLine(EventProvider.GetLastWriteEventError());
}
provider.Close();
注解
如果调用 SetActivityId 方法为事件指定活动标识符,则此方法将从线程上下文中检索标识符,并将其包括在事件中。If you call the SetActivityId method to specify an activity identifier for the event, this method retrieves the identifier from the thread context and includes it with the event.
最大字符串长度限制为 64 KB 减去事件标头的大小。The maximum string length is limited to 64 KB minus the size of the event headers. 如果会话的缓冲区较小,而且会话中包括事件的扩展数据项,则该事件会较小。The event size is less if the session's buffer size is less and the session includes extended data items with the event.
适用于
WriteEvent(EventDescriptor, Int32, IntPtr)
写入某个事件。Writes an event. 以内存块形式指定事件数据。The event data is specified as a block of memory.
protected:
bool WriteEvent(System::Diagnostics::Eventing::EventDescriptor % eventDescriptor, int dataCount, IntPtr data);
[System.Security.SecurityCritical]
protected bool WriteEvent (ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, int dataCount, IntPtr data);
[<System.Security.SecurityCritical>]
member this.WriteEvent : EventDescriptor * int * nativeint -> bool
Protected Function WriteEvent (ByRef eventDescriptor As EventDescriptor, dataCount As Integer, data As IntPtr) As Boolean
参数
- eventDescriptor
- EventDescriptor
用来标识要写入的事件的 EventDescriptor 实例。An instance of EventDescriptor that identifies the event to write.
- dataCount
- Int32
data 参数所指向的事件数据的大小。Size of the event data to which the data parameter points. 事件数据的最大大小限制为 64 KB 减去事件头大小所得的值。The maximum event data size is limited to 64 KB minus the size of the event headers. 如果会话的缓冲区较小,而且会话中包括事件的扩展数据项,则该事件会较小。The event size is less if the session's buffer size is less and the session includes extended data items with the event.
- data
- IntPtr
指向要写入的事件数据的指针。Pointer to the event data to write.
返回
如果写入此事件,则为 true;否则为 false。Is true if the event is written; otherwise, false. 如果为 false,则调用 GetLastWriteEventError() 方法来确定失败的原因。If false, call the GetLastWriteEventError() method to determine the cause of the failure.
- 属性
注解
如果调用 SetActivityId 方法为事件指定活动标识符,则此方法将从线程上下文中检索标识符,并将其包括在事件中。If you call the SetActivityId method to specify an activity identifier for the event, this method retrieves the identifier from the thread context and includes it with the event.