#if NET20
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Event methods and classes literally pulled from the .NET 4.0 implementation.
* None of this is original work. It comes straight from decompiled Microsoft
* assemblies.
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
using Microsoft.Win32.SafeHandles;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
using System.Security.Principal;
using System.Text;
namespace System.Diagnostics.Eventing.Reader
{
internal enum PathType
{
FilePath = 2,
LogName = 1
}
internal enum SessionAuthentication
{
Default,
Negotiate,
Kerberos,
Ntlm
}
internal enum EventLogIsolation
{
Application,
System,
Custom
}
internal enum EventLogMode
{
Circular,
AutoBackup,
Retain
}
internal enum EventLogType
{
Administrative,
Operational,
Analytical,
Debug
}
///
/// Defines the standard keywords that are attached to events by the event provider. For more information about keywords, see
/// Represents a placeholder (bookmark) within an event stream. You can use the placeholder to mark a position and return to this position in a stream of events. An instance of this object can be obtained from an EventRecord object, in which case it corresponds to the position of that event record.
///
[Serializable, HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public class EventBookmark : ISerializable
{
// Fields
private string bookmark;
// Methods
internal EventBookmark(string bookmarkText)
{
if (bookmarkText == null)
{
throw new ArgumentNullException("bookmarkText");
}
this.bookmark = bookmarkText;
}
///
/// Initializes a new instance of the class.
///
/// The information.
/// The context.
protected EventBookmark(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
this.bookmark = info.GetString("BookmarkText");
}
// Properties
internal string BookmarkText
{
get
{
return this.bookmark;
}
}
[SecurityCritical, SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
this.GetObjectData(info, context);
}
///
/// Gets the object data.
///
/// The information.
/// The context.
[SecurityCritical, SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
protected virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
info.AddValue("BookmarkText", this.bookmark);
}
}
///
/// Represents a keyword for an event. Keywords are defined in an event provider and are used to group the event with other similar events (based on the usage of the events).
///
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal sealed class EventKeyword
{
// Fields
private bool dataReady;
private string displayName;
private string name;
private ProviderMetadata pmReference;
private object syncObject;
private long value;
// Methods
internal EventKeyword(long value, ProviderMetadata pmReference)
{
this.value = value;
this.pmReference = pmReference;
this.syncObject = new object();
}
internal EventKeyword(string name, long value, string displayName)
{
this.value = value;
this.name = name;
this.displayName = displayName;
this.dataReady = true;
this.syncObject = new object();
}
// Properties
///
/// Gets the display name.
///
///
/// The display name.
///
public string DisplayName
{
get
{
this.PrepareData();
return this.displayName;
}
}
///
/// Gets the name.
///
///
/// The name.
///
public string Name
{
get
{
this.PrepareData();
return this.name;
}
}
///
/// Gets the value.
///
///
/// The value.
///
public long Value
{
get
{
return this.value;
}
}
internal void PrepareData()
{
if (!this.dataReady)
{
lock (this.syncObject)
{
if (!this.dataReady)
{
IEnumerable keywords = this.pmReference.Keywords;
this.name = null;
this.displayName = null;
this.dataReady = true;
foreach (EventKeyword keyword in keywords)
{
if (keyword.Value == this.value)
{
this.name = keyword.Name;
this.displayName = keyword.DisplayName;
break;
}
}
}
}
}
}
}
///
/// Contains an event level that is defined in an event provider. The level signifies the severity of the event.
///
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal sealed class EventLevel
{
// Fields
private bool dataReady;
private string displayName;
private string name;
private ProviderMetadata pmReference;
private object syncObject;
private int value;
// Methods
internal EventLevel(int value, ProviderMetadata pmReference)
{
this.value = value;
this.pmReference = pmReference;
this.syncObject = new object();
}
internal EventLevel(string name, int value, string displayName)
{
this.value = value;
this.name = name;
this.displayName = displayName;
this.dataReady = true;
this.syncObject = new object();
}
// Properties
///
/// Gets the display name.
///
///
/// The display name.
///
public string DisplayName
{
get
{
this.PrepareData();
return this.displayName;
}
}
///
/// Gets the name.
///
///
/// The name.
///
public string Name
{
get
{
this.PrepareData();
return this.name;
}
}
///
/// Gets the value.
///
///
/// The value.
///
public int Value
{
get
{
return this.value;
}
}
internal void PrepareData()
{
if (!this.dataReady)
{
lock (this.syncObject)
{
if (!this.dataReady)
{
IEnumerable levels = this.pmReference.Levels;
this.name = null;
this.displayName = null;
this.dataReady = true;
foreach (EventLevel level in levels)
{
if (level.Value == this.value)
{
this.name = level.Name;
this.displayName = level.DisplayName;
break;
}
}
}
}
}
}
}
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal class EventLogConfiguration : IDisposable
{
private string channelName;
private EventLogHandle handle;
private EventLogSession session;
public EventLogConfiguration(string logName) : this(logName, null) { }
[SecurityCritical]
public EventLogConfiguration(string logName, EventLogSession session)
{
this.handle = EventLogHandle.Zero;
EventLogPermissionHolder.GetEventLogPermission().Demand();
if (session == null)
{
session = EventLogSession.GlobalSession;
}
this.session = session;
this.channelName = logName;
this.handle = NativeWrapper.EvtOpenChannelConfig(this.session.Handle, this.channelName, 0);
}
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
[SecuritySafeCritical]
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
}
if ((this.handle != null) && !this.handle.IsInvalid)
{
this.handle.Dispose();
}
}
public void SaveChanges()
{
NativeWrapper.EvtSaveChannelConfig(this.handle, 0);
}
// Properties
public bool IsClassicLog
{
get
{
return (bool)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelConfigClassicEventlog);
}
}
public bool IsEnabled
{
get
{
return (bool)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelConfigEnabled);
}
set
{
NativeWrapper.EvtSetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelConfigEnabled, value);
}
}
public string LogFilePath
{
get
{
return (string)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelLoggingConfigLogFilePath);
}
set
{
NativeWrapper.EvtSetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelLoggingConfigLogFilePath, value);
}
}
public EventLogIsolation LogIsolation
{
get
{
return (EventLogIsolation)((uint)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelConfigIsolation));
}
}
public EventLogMode LogMode
{
get
{
object obj2 = NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelLoggingConfigRetention);
object obj3 = NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelLoggingConfigAutoBackup);
bool flag = (obj2 != null) && ((bool)obj2);
if ((obj3 != null) && ((bool)obj3))
{
return EventLogMode.AutoBackup;
}
if (flag)
{
return EventLogMode.Retain;
}
return EventLogMode.Circular;
}
set
{
switch (value)
{
case EventLogMode.Circular:
NativeWrapper.EvtSetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelLoggingConfigAutoBackup, false);
NativeWrapper.EvtSetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelLoggingConfigRetention, false);
return;
case EventLogMode.AutoBackup:
NativeWrapper.EvtSetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelLoggingConfigAutoBackup, true);
NativeWrapper.EvtSetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelLoggingConfigRetention, true);
return;
case EventLogMode.Retain:
NativeWrapper.EvtSetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelLoggingConfigAutoBackup, false);
NativeWrapper.EvtSetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelLoggingConfigRetention, true);
return;
}
}
}
public string LogName
{
get
{
return this.channelName;
}
}
public EventLogType LogType
{
get
{
return (EventLogType)((uint)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelConfigType));
}
}
public long MaximumSizeInBytes
{
get
{
return (long)((ulong)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelLoggingConfigMaxSize));
}
set
{
NativeWrapper.EvtSetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelLoggingConfigMaxSize, value);
}
}
public string OwningProviderName
{
get
{
return (string)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelConfigOwningPublisher);
}
}
public int? ProviderBufferSize
{
get
{
uint? nullable = (uint?)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelPublishingConfigBufferSize);
if (!nullable.HasValue)
{
return null;
}
return new int?((int)nullable.GetValueOrDefault());
}
}
public Guid? ProviderControlGuid
{
get
{
return (Guid?)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelPublishingConfigControlGuid);
}
}
public long? ProviderKeywords
{
get
{
ulong? nullable = (ulong?)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelPublishingConfigKeywords);
if (!nullable.HasValue)
{
return null;
}
return new long?((long)nullable.GetValueOrDefault());
}
set
{
NativeWrapper.EvtSetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelPublishingConfigKeywords, value);
}
}
public int? ProviderLatency
{
get
{
uint? nullable = (uint?)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelPublishingConfigLatency);
if (!nullable.HasValue)
{
return null;
}
return new int?((int)nullable.GetValueOrDefault());
}
}
public int? ProviderLevel
{
get
{
uint? nullable = (uint?)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelPublishingConfigLevel);
if (!nullable.HasValue)
{
return null;
}
return new int?((int)nullable.GetValueOrDefault());
}
set
{
NativeWrapper.EvtSetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelPublishingConfigLevel, value);
}
}
public int? ProviderMaximumNumberOfBuffers
{
get
{
uint? nullable = (uint?)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelPublishingConfigMaxBuffers);
if (!nullable.HasValue)
{
return null;
}
return new int?((int)nullable.GetValueOrDefault());
}
}
public int? ProviderMinimumNumberOfBuffers
{
get
{
uint? nullable = (uint?)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelPublishingConfigMinBuffers);
if (!nullable.HasValue)
{
return null;
}
return new int?((int)nullable.GetValueOrDefault());
}
}
public IEnumerable ProviderNames
{
get
{
return (string[])NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelPublisherList);
}
}
public string SecurityDescriptor
{
get
{
return (string)NativeWrapper.EvtGetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelConfigAccess);
}
set
{
NativeWrapper.EvtSetChannelConfigProperty(this.handle, UnsafeNativeMethods.EvtChannelConfigPropertyId.EvtChannelConfigAccess, value);
}
}
}
[Serializable, HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal class EventLogException : Exception, ISerializable
{
// Fields
private int errorCode;
// Methods
public EventLogException()
{
}
public EventLogException(string message)
: base(message)
{
}
public EventLogException(string message, Exception innerException)
: base(message, innerException)
{
}
protected EventLogException(int errorCode)
{
this.errorCode = errorCode;
}
protected EventLogException(SerializationInfo serializationInfo, StreamingContext streamingContext)
: base(serializationInfo, streamingContext)
{
}
// Properties
public override string Message
{
[SecurityCritical]
get
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
Win32Exception exception = new Win32Exception(this.errorCode);
return exception.Message;
}
}
[SecurityCritical, SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
info.AddValue("errorCode", this.errorCode);
base.GetObjectData(info, context);
}
internal static void Throw(int errorCode)
{
switch (errorCode)
{
case 0x4c7:
case 0x71a:
throw new OperationCanceledException();
case 2:
case 3:
case 0x3a9f:
case 0x3a9a:
case 0x3ab3:
case 0x3ab4:
throw new EventLogNotFoundException(errorCode);
case 5:
throw new UnauthorizedAccessException();
case 13:
case 0x3a9d:
throw new EventLogInvalidDataException(errorCode);
case 0x3aa3:
case 0x3aa4:
throw new EventLogReadingException(errorCode);
case 0x3abd:
throw new EventLogProviderDisabledException(errorCode);
}
throw new EventLogException(errorCode);
}
}
///
/// Allows you to access the run-time properties of active event logs and event log files. These properties include the number of events in the log, the size of the log, a value that determines whether the log is full, and the last time the log was written to or accessed.
///
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal sealed class EventLogInformation
{
// Fields
private DateTime? creationTime;
private int? fileAttributes;
private long? fileSize;
private bool? isLogFull;
private DateTime? lastAccessTime;
private DateTime? lastWriteTime;
private long? oldestRecordNumber;
private long? recordCount;
// Methods
[SecurityTreatAsSafe, SecurityCritical]
internal EventLogInformation(EventLogSession session, string channelName, PathType pathType)
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
EventLogHandle handle = NativeWrapper.EvtOpenLog(session.Handle, channelName, pathType);
using (handle)
{
this.creationTime = (DateTime?)NativeWrapper.EvtGetLogInfo(handle, UnsafeNativeMethods.EvtLogPropertyId.EvtLogCreationTime);
this.lastAccessTime = (DateTime?)NativeWrapper.EvtGetLogInfo(handle, UnsafeNativeMethods.EvtLogPropertyId.EvtLogLastAccessTime);
this.lastWriteTime = (DateTime?)NativeWrapper.EvtGetLogInfo(handle, UnsafeNativeMethods.EvtLogPropertyId.EvtLogLastWriteTime);
ulong? nullable = (ulong?)NativeWrapper.EvtGetLogInfo(handle, UnsafeNativeMethods.EvtLogPropertyId.EvtLogFileSize);
this.fileSize = nullable.HasValue ? (long?)(nullable.GetValueOrDefault()) : null;
uint? nullable3 = (uint?)NativeWrapper.EvtGetLogInfo(handle, UnsafeNativeMethods.EvtLogPropertyId.EvtLogAttributes);
this.fileAttributes = nullable3.HasValue ? (int?)(nullable3.GetValueOrDefault()) : null;
ulong? nullable5 = (ulong?)NativeWrapper.EvtGetLogInfo(handle, UnsafeNativeMethods.EvtLogPropertyId.EvtLogNumberOfLogRecords);
this.recordCount = nullable5.HasValue ? (long?)(nullable5.GetValueOrDefault()) : null;
ulong? nullable7 = (ulong?)NativeWrapper.EvtGetLogInfo(handle, UnsafeNativeMethods.EvtLogPropertyId.EvtLogOldestRecordNumber);
this.oldestRecordNumber = nullable7.HasValue ? (long?)(nullable7.GetValueOrDefault()) : null;
this.isLogFull = (bool?)NativeWrapper.EvtGetLogInfo(handle, UnsafeNativeMethods.EvtLogPropertyId.EvtLogFull);
}
}
// Properties
///
/// Gets the attributes.
///
///
/// The attributes.
///
public int? Attributes
{
get
{
return this.fileAttributes;
}
}
///
/// Gets the creation time.
///
///
/// The creation time.
///
public DateTime? CreationTime
{
get
{
return this.creationTime;
}
}
///
/// Gets the size of the file.
///
///
/// The size of the file.
///
public long? FileSize
{
get
{
return this.fileSize;
}
}
///
/// Gets the is log full.
///
///
/// The is log full.
///
public bool? IsLogFull
{
get
{
return this.isLogFull;
}
}
///
/// Gets the last access time.
///
///
/// The last access time.
///
public DateTime? LastAccessTime
{
get
{
return this.lastAccessTime;
}
}
///
/// Gets the last write time.
///
///
/// The last write time.
///
public DateTime? LastWriteTime
{
get
{
return this.lastWriteTime;
}
}
///
/// Gets the oldest record number.
///
///
/// The oldest record number.
///
public long? OldestRecordNumber
{
get
{
return this.oldestRecordNumber;
}
}
///
/// Gets the record count.
///
///
/// The record count.
///
public long? RecordCount
{
get
{
return this.recordCount;
}
}
}
[Serializable, HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal class EventLogInvalidDataException : EventLogException
{
// Methods
public EventLogInvalidDataException()
{
}
public EventLogInvalidDataException(string message)
: base(message)
{
}
public EventLogInvalidDataException(string message, Exception innerException)
: base(message, innerException)
{
}
internal EventLogInvalidDataException(int errorCode)
: base(errorCode)
{
}
protected EventLogInvalidDataException(SerializationInfo serializationInfo, StreamingContext streamingContext)
: base(serializationInfo, streamingContext)
{
}
}
///
/// Represents a link between an event provider and an event log that the provider publishes events into. This object cannot be instantiated.
///
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal sealed class EventLogLink
{
// Fields
private uint channelId;
private string channelName;
private bool dataReady;
private string displayName;
private bool isImported;
private ProviderMetadata pmReference;
private object syncObject;
// Methods
internal EventLogLink(uint channelId, ProviderMetadata pmReference)
{
this.channelId = channelId;
this.pmReference = pmReference;
this.syncObject = new object();
}
internal EventLogLink(string channelName, bool isImported, string displayName, uint channelId)
{
this.channelName = channelName;
this.isImported = isImported;
this.displayName = displayName;
this.channelId = channelId;
this.dataReady = true;
this.syncObject = new object();
}
///
/// Gets the display name.
///
///
/// The display name.
///
public string DisplayName
{
get
{
this.PrepareData();
return this.displayName;
}
}
///
/// Gets a value indicating whether this instance is imported.
///
///
/// true if this instance is imported; otherwise, false.
///
public bool IsImported
{
get
{
this.PrepareData();
return this.isImported;
}
}
///
/// Gets the name of the log.
///
///
/// The name of the log.
///
public string LogName
{
get
{
this.PrepareData();
return this.channelName;
}
}
// Properties
internal uint ChannelId
{
get
{
return this.channelId;
}
}
private void PrepareData()
{
if (!this.dataReady)
{
lock (this.syncObject)
{
if (!this.dataReady)
{
IEnumerable logLinks = this.pmReference.LogLinks;
this.channelName = null;
this.isImported = false;
this.displayName = null;
this.dataReady = true;
foreach (EventLogLink link in logLinks)
{
if (link.ChannelId == this.channelId)
{
this.channelName = link.LogName;
this.isImported = link.IsImported;
this.displayName = link.DisplayName;
this.dataReady = true;
break;
}
}
}
}
}
}
}
[Serializable, HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal class EventLogNotFoundException : EventLogException
{
// Methods
public EventLogNotFoundException()
{
}
public EventLogNotFoundException(string message)
: base(message)
{
}
public EventLogNotFoundException(string message, Exception innerException)
: base(message, innerException)
{
}
internal EventLogNotFoundException(int errorCode)
: base(errorCode)
{
}
protected EventLogNotFoundException(SerializationInfo serializationInfo, StreamingContext streamingContext)
: base(serializationInfo, streamingContext)
{
}
}
///
/// Contains an array of strings that represent XPath queries for elements in the XML representation of an event, which is based on the Event Schema. The queries in this object are used to extract values from the event.
///
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public class EventLogPropertySelector : IDisposable
{
// Fields
private EventLogHandle renderContextHandleValues;
// Methods
///
/// Initializes a new instance of the class.
///
/// The property queries.
[SecurityCritical]
public EventLogPropertySelector(IEnumerable propertyQueries)
{
string[] strArray;
EventLogPermissionHolder.GetEventLogPermission().Demand();
if (propertyQueries == null)
{
throw new ArgumentNullException("propertyQueries");
}
ICollection is2 = propertyQueries as ICollection;
if (is2 != null)
{
strArray = new string[is2.Count];
is2.CopyTo(strArray, 0);
}
else
{
strArray = new List(propertyQueries).ToArray();
}
this.renderContextHandleValues = NativeWrapper.EvtCreateRenderContext(strArray.Length, strArray, UnsafeNativeMethods.EvtRenderContextFlags.EvtRenderContextValues);
}
// Properties
internal EventLogHandle Handle
{
get
{
return this.renderContextHandleValues;
}
}
///
/// Releases unmanaged and - optionally - managed resources.
///
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
///
/// Releases unmanaged and - optionally - managed resources.
///
/// true to release both managed and unmanaged resources; false to release only unmanaged resources.
[SecurityTreatAsSafe, SecurityCritical]
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
}
if ((this.renderContextHandleValues != null) && !this.renderContextHandleValues.IsInvalid)
{
this.renderContextHandleValues.Dispose();
}
}
}
[Serializable, HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal class EventLogProviderDisabledException : EventLogException
{
// Methods
public EventLogProviderDisabledException()
{
}
public EventLogProviderDisabledException(string message)
: base(message)
{
}
public EventLogProviderDisabledException(string message, Exception innerException)
: base(message, innerException)
{
}
internal EventLogProviderDisabledException(int errorCode)
: base(errorCode)
{
}
protected EventLogProviderDisabledException(SerializationInfo serializationInfo, StreamingContext streamingContext)
: base(serializationInfo, streamingContext)
{
}
}
internal class EventLogQuery
{
// Fields
private string path;
private PathType pathType;
private string query;
private bool reverseDirection;
private EventLogSession session;
private bool tolerateErrors;
// Methods
public EventLogQuery(string path, PathType pathType)
: this(path, pathType, null)
{
}
public EventLogQuery(string path, PathType pathType, string query)
{
this.session = EventLogSession.GlobalSession;
this.path = path;
this.pathType = pathType;
if (query == null)
{
if (path == null)
{
throw new ArgumentNullException("path");
}
}
else
{
this.query = query;
}
}
public bool ReverseDirection
{
get
{
return this.reverseDirection;
}
set
{
this.reverseDirection = value;
}
}
public EventLogSession Session
{
get
{
return this.session;
}
set
{
this.session = value;
}
}
public bool TolerateQueryErrors
{
get
{
return this.tolerateErrors;
}
set
{
this.tolerateErrors = value;
}
}
// Properties
internal string Path
{
get
{
return this.path;
}
}
internal string Query
{
get
{
return this.query;
}
}
internal PathType ThePathType
{
get
{
return this.pathType;
}
}
}
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true), HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal class EventLogReader : IDisposable
{
// Fields
private int batchSize;
private ProviderMetadataCachedInformation cachedMetadataInformation;
private int currentIndex;
private int eventCount;
private EventLogQuery eventQuery;
private IntPtr[] eventsBuffer;
private EventLogHandle handle;
private bool isEof;
// Methods
public EventLogReader(EventLogQuery eventQuery)
: this(eventQuery, null)
{
}
public EventLogReader(string path)
: this(new EventLogQuery(path, PathType.LogName), null)
{
}
[SecurityCritical]
public EventLogReader(EventLogQuery eventQuery, EventBookmark bookmark)
{
if (eventQuery == null)
{
throw new ArgumentNullException("eventQuery");
}
string logfile = null;
if (eventQuery.ThePathType == PathType.FilePath)
{
logfile = eventQuery.Path;
}
this.cachedMetadataInformation = new ProviderMetadataCachedInformation(eventQuery.Session, logfile, 50);
this.eventQuery = eventQuery;
this.batchSize = 0x40;
this.eventsBuffer = new IntPtr[this.batchSize];
int flags = 0;
if (this.eventQuery.ThePathType == PathType.LogName)
{
flags |= 1;
}
else
{
flags |= 2;
}
if (this.eventQuery.ReverseDirection)
{
flags |= 0x200;
}
if (this.eventQuery.TolerateQueryErrors)
{
flags |= 0x1000;
}
EventLogPermissionHolder.GetEventLogPermission().Demand();
this.handle = NativeWrapper.EvtQuery(this.eventQuery.Session.Handle, this.eventQuery.Path, this.eventQuery.Query, flags);
EventLogHandle bookmarkHandleFromBookmark = EventLogRecord.GetBookmarkHandleFromBookmark(bookmark);
if (!bookmarkHandleFromBookmark.IsInvalid)
{
using (bookmarkHandleFromBookmark)
{
NativeWrapper.EvtSeek(this.handle, 1L, bookmarkHandleFromBookmark, 0, UnsafeNativeMethods.EvtSeekFlags.EvtSeekRelativeToBookmark);
}
}
}
public EventLogReader(string path, PathType pathType)
: this(new EventLogQuery(path, pathType), null)
{
}
// Properties
public int BatchSize
{
get
{
return this.batchSize;
}
set
{
if (value < 1)
{
throw new ArgumentOutOfRangeException("value");
}
this.batchSize = value;
}
}
public IList LogStatus
{
[SecurityCritical]
get
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
List list = null;
string[] strArray = null;
int[] numArray = null;
EventLogHandle handle = this.handle;
if (handle.IsInvalid)
{
throw new InvalidOperationException();
}
strArray = (string[])NativeWrapper.EvtGetQueryInfo(handle, UnsafeNativeMethods.EvtQueryPropertyId.EvtQueryNames);
numArray = (int[])NativeWrapper.EvtGetQueryInfo(handle, UnsafeNativeMethods.EvtQueryPropertyId.EvtQueryStatuses);
if (strArray.Length != numArray.Length)
{
throw new InvalidOperationException();
}
list = new List(strArray.Length);
for (int i = 0; i < strArray.Length; i++)
{
EventLogStatus item = new EventLogStatus(strArray[i], numArray[i]);
list.Add(item);
}
return list.AsReadOnly();
}
}
public void CancelReading()
{
NativeWrapper.EvtCancel(this.handle);
}
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
public EventRecord ReadEvent()
{
return this.ReadEvent(TimeSpan.MaxValue);
}
[SecurityCritical]
public EventRecord ReadEvent(TimeSpan timeout)
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
if (this.isEof)
{
throw new InvalidOperationException();
}
if (this.currentIndex >= this.eventCount)
{
this.GetNextBatch(timeout);
if (this.currentIndex >= this.eventCount)
{
this.isEof = true;
return null;
}
}
EventLogRecord record = new EventLogRecord(new EventLogHandle(this.eventsBuffer[this.currentIndex], true), this.eventQuery.Session, this.cachedMetadataInformation);
this.currentIndex++;
return record;
}
public void Seek(EventBookmark bookmark)
{
this.Seek(bookmark, 0L);
}
[SecurityCritical]
public void Seek(EventBookmark bookmark, long offset)
{
if (bookmark == null)
{
throw new ArgumentNullException("bookmark");
}
EventLogPermissionHolder.GetEventLogPermission().Demand();
this.SeekReset();
using (EventLogHandle handle = EventLogRecord.GetBookmarkHandleFromBookmark(bookmark))
{
NativeWrapper.EvtSeek(this.handle, offset, handle, 0, UnsafeNativeMethods.EvtSeekFlags.EvtSeekRelativeToBookmark);
}
}
[SecurityCritical]
public void Seek(SeekOrigin origin, long offset)
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
switch (origin)
{
case SeekOrigin.Begin:
this.SeekReset();
NativeWrapper.EvtSeek(this.handle, offset, EventLogHandle.Zero, 0, UnsafeNativeMethods.EvtSeekFlags.EvtSeekRelativeToFirst);
return;
case SeekOrigin.Current:
if (offset < 0L)
{
if ((this.currentIndex + offset) >= 0L)
{
this.SeekCommon(offset);
}
else
{
this.SeekCommon(offset);
}
return;
}
if ((this.currentIndex + offset) >= this.eventCount)
{
this.SeekCommon(offset);
return;
}
for (int i = this.currentIndex; i < (this.currentIndex + offset); i++)
{
NativeWrapper.EvtClose(this.eventsBuffer[i]);
}
this.currentIndex += (int)offset;
return;
case SeekOrigin.End:
this.SeekReset();
NativeWrapper.EvtSeek(this.handle, offset, EventLogHandle.Zero, 0, UnsafeNativeMethods.EvtSeekFlags.EvtSeekRelativeToLast);
return;
}
}
[SecurityCritical]
internal void SeekCommon(long offset)
{
offset -= this.eventCount - this.currentIndex;
this.SeekReset();
NativeWrapper.EvtSeek(this.handle, offset, EventLogHandle.Zero, 0, UnsafeNativeMethods.EvtSeekFlags.EvtSeekRelativeToCurrent);
}
[SecurityCritical]
internal void SeekReset()
{
while (this.currentIndex < this.eventCount)
{
NativeWrapper.EvtClose(this.eventsBuffer[this.currentIndex]);
this.currentIndex++;
}
this.currentIndex = 0;
this.eventCount = 0;
this.isEof = false;
}
[SecurityCritical, SecurityTreatAsSafe]
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
}
while (this.currentIndex < this.eventCount)
{
NativeWrapper.EvtClose(this.eventsBuffer[this.currentIndex]);
this.currentIndex++;
}
if ((this.handle != null) && !this.handle.IsInvalid)
{
this.handle.Dispose();
}
}
[SecurityCritical]
private bool GetNextBatch(TimeSpan ts)
{
int totalMilliseconds;
if (ts == TimeSpan.MaxValue)
{
totalMilliseconds = -1;
}
else
{
totalMilliseconds = (int)ts.TotalMilliseconds;
}
if (this.batchSize != this.eventsBuffer.Length)
{
this.eventsBuffer = new IntPtr[this.batchSize];
}
int returned = 0;
if (!NativeWrapper.EvtNext(this.handle, this.batchSize, this.eventsBuffer, totalMilliseconds, 0, ref returned))
{
this.eventCount = 0;
this.currentIndex = 0;
return false;
}
this.currentIndex = 0;
this.eventCount = returned;
return true;
}
}
[Serializable, HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal class EventLogReadingException : EventLogException
{
// Methods
public EventLogReadingException()
{
}
public EventLogReadingException(string message)
: base(message)
{
}
public EventLogReadingException(string message, Exception innerException)
: base(message, innerException)
{
}
internal EventLogReadingException(int errorCode)
: base(errorCode)
{
}
protected EventLogReadingException(SerializationInfo serializationInfo, StreamingContext streamingContext)
: base(serializationInfo, streamingContext)
{
}
}
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal class EventLogRecord : EventRecord
{
[SecurityTreatAsSafe]
internal EventLogRecord(EventLogHandle handle, EventLogSession session, ProviderMetadataCachedInformation cachedMetadataInfo)
: base(handle, session, cachedMetadataInfo)
{
}
}
internal class EventLogSession : IDisposable
{
internal EventLogHandle renderContextHandleSystem;
internal EventLogHandle renderContextHandleUser;
private static EventLogSession globalSession = new EventLogSession();
// Fields
private string domain;
private EventLogHandle handle;
private SessionAuthentication logOnType;
private string server;
private object syncObject;
private string user;
// Methods
[SecurityCritical]
public EventLogSession()
{
this.renderContextHandleSystem = EventLogHandle.Zero;
this.renderContextHandleUser = EventLogHandle.Zero;
this.handle = EventLogHandle.Zero;
EventLogPermissionHolder.GetEventLogPermission().Demand();
this.syncObject = new object();
}
public EventLogSession(string server)
: this(server, null, null, null, SessionAuthentication.Default)
{
}
[SecurityCritical]
public EventLogSession(string server, string domain, string user, SecureString password, SessionAuthentication logOnType)
{
this.renderContextHandleSystem = EventLogHandle.Zero;
this.renderContextHandleUser = EventLogHandle.Zero;
this.handle = EventLogHandle.Zero;
EventLogPermissionHolder.GetEventLogPermission().Demand();
if (server == null)
{
server = "localhost";
}
this.syncObject = new object();
this.server = server;
this.domain = domain;
this.user = user;
this.logOnType = logOnType;
UnsafeNativeMethods.EvtRpcLogin login = new UnsafeNativeMethods.EvtRpcLogin();
login.Server = this.server;
login.User = this.user;
login.Domain = this.domain;
login.Flags = (int)this.logOnType;
login.Password = CoTaskMemUnicodeSafeHandle.Zero;
try
{
if (password != null)
{
login.Password.SetMemory(Marshal.SecureStringToCoTaskMemUnicode(password));
}
this.handle = NativeWrapper.EvtOpenSession(UnsafeNativeMethods.EvtLoginClass.EvtRpcLogin, ref login, 0, 0);
}
finally
{
login.Password.Close();
}
}
// Properties
public static EventLogSession GlobalSession
{
get
{
return globalSession;
}
}
internal EventLogHandle Handle
{
get
{
return this.handle;
}
}
public void CancelCurrentOperations()
{
NativeWrapper.EvtCancel(this.handle);
}
public void ClearLog(string logName)
{
this.ClearLog(logName, null);
}
public void ClearLog(string logName, string backupPath)
{
if (logName == null)
{
throw new ArgumentNullException("logName");
}
NativeWrapper.EvtClearLog(this.Handle, logName, backupPath, 0);
}
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
public void ExportLog(string path, PathType pathType, string query, string targetFilePath)
{
this.ExportLog(path, pathType, query, targetFilePath, false);
}
public void ExportLog(string path, PathType pathType, string query, string targetFilePath, bool tolerateQueryErrors)
{
UnsafeNativeMethods.EvtExportLogFlags evtExportLogChannelPath;
if (path == null)
{
throw new ArgumentNullException("path");
}
if (targetFilePath == null)
{
throw new ArgumentNullException("targetFilePath");
}
switch (pathType)
{
case PathType.LogName:
evtExportLogChannelPath = UnsafeNativeMethods.EvtExportLogFlags.EvtExportLogChannelPath;
break;
case PathType.FilePath:
evtExportLogChannelPath = UnsafeNativeMethods.EvtExportLogFlags.EvtExportLogFilePath;
break;
default:
throw new ArgumentOutOfRangeException("pathType");
}
if (!tolerateQueryErrors)
{
NativeWrapper.EvtExportLog(this.Handle, path, query, targetFilePath, (int)evtExportLogChannelPath);
}
else
{
NativeWrapper.EvtExportLog(this.Handle, path, query, targetFilePath, ((int)evtExportLogChannelPath) | 0x1000);
}
}
public void ExportLogAndMessages(string path, PathType pathType, string query, string targetFilePath)
{
this.ExportLogAndMessages(path, pathType, query, targetFilePath, false, CultureInfo.CurrentCulture);
}
public void ExportLogAndMessages(string path, PathType pathType, string query, string targetFilePath, bool tolerateQueryErrors, CultureInfo targetCultureInfo)
{
if (targetCultureInfo == null)
{
targetCultureInfo = CultureInfo.CurrentCulture;
}
this.ExportLog(path, pathType, query, targetFilePath, tolerateQueryErrors);
NativeWrapper.EvtArchiveExportedLog(this.Handle, targetFilePath, targetCultureInfo.LCID, 0);
}
public EventLogInformation GetLogInformation(string logName, PathType pathType)
{
if (logName == null)
{
throw new ArgumentNullException("logName");
}
return new EventLogInformation(this, logName, pathType);
}
[SecurityCritical]
public IEnumerable GetLogNames()
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
List list = new List(100);
using (EventLogHandle handle = NativeWrapper.EvtOpenChannelEnum(this.Handle, 0))
{
bool finish = false;
do
{
string item = NativeWrapper.EvtNextChannelPath(handle, ref finish);
if (!finish)
{
list.Add(item);
}
}
while (!finish);
return list;
}
}
[SecurityCritical]
public IEnumerable GetProviderNames()
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
List list = new List(100);
using (EventLogHandle handle = NativeWrapper.EvtOpenProviderEnum(this.Handle, 0))
{
bool finish = false;
do
{
string item = NativeWrapper.EvtNextPublisherId(handle, ref finish);
if (!finish)
{
list.Add(item);
}
}
while (!finish);
return list;
}
}
[SecurityTreatAsSafe, SecurityCritical]
internal void SetupSystemContext()
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
if (this.renderContextHandleSystem.IsInvalid)
{
lock (this.syncObject)
{
if (this.renderContextHandleSystem.IsInvalid)
{
this.renderContextHandleSystem = NativeWrapper.EvtCreateRenderContext(0, null, UnsafeNativeMethods.EvtRenderContextFlags.EvtRenderContextSystem);
}
}
}
}
[SecurityCritical, SecurityTreatAsSafe]
internal void SetupUserContext()
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
lock (this.syncObject)
{
if (this.renderContextHandleUser.IsInvalid)
{
this.renderContextHandleUser = NativeWrapper.EvtCreateRenderContext(0, null, UnsafeNativeMethods.EvtRenderContextFlags.EvtRenderContextUser);
}
}
}
[SecurityTreatAsSafe, SecurityCritical]
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (this == globalSession)
{
throw new InvalidOperationException();
}
EventLogPermissionHolder.GetEventLogPermission().Demand();
}
if ((this.renderContextHandleSystem != null) && !this.renderContextHandleSystem.IsInvalid)
{
this.renderContextHandleSystem.Dispose();
}
if ((this.renderContextHandleUser != null) && !this.renderContextHandleUser.IsInvalid)
{
this.renderContextHandleUser.Dispose();
}
if ((this.handle != null) && !this.handle.IsInvalid)
{
this.handle.Dispose();
}
}
}
///
/// Contains the status code or error code for a specific event log. This status can be used to determine if the event log is available for an operation.
///
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal sealed class EventLogStatus
{
// Fields
private string channelName;
private int win32ErrorCode;
// Methods
internal EventLogStatus(string channelName, int win32ErrorCode)
{
this.channelName = channelName;
this.win32ErrorCode = win32ErrorCode;
}
// Properties
///
/// Gets the name of the log.
///
///
/// The name of the log.
///
public string LogName
{
get
{
return this.channelName;
}
}
///
/// Gets the status code.
///
///
/// The status code.
///
public int StatusCode
{
get
{
return this.win32ErrorCode;
}
}
}
///
/// Contains the metadata (properties and settings) for an event that is defined in an event provider.
///
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal sealed class EventMetadata
{
// Fields
private byte channelId;
private string description;
private long id;
private long keywords;
private byte level;
private short opcode;
private ProviderMetadata pmReference;
private int task;
private string template;
private byte version;
// Methods
internal EventMetadata(uint id, byte version, byte channelId, byte level, byte opcode, short task, long keywords, string template, string description, ProviderMetadata pmReference)
{
this.id = id;
this.version = version;
this.channelId = channelId;
this.level = level;
this.opcode = opcode;
this.task = task;
this.keywords = keywords;
this.template = template;
this.description = description;
this.pmReference = pmReference;
}
// Properties
///
/// Gets the description.
///
///
/// The description.
///
public string Description
{
get
{
return this.description;
}
}
///
/// Gets the identifier.
///
///
/// The identifier.
///
public long Id
{
get
{
return this.id;
}
}
///
/// Gets the keywords.
///
///
/// The keywords.
///
public IEnumerable Keywords
{
get
{
List list = new List();
ulong keywords = (ulong)this.keywords;
ulong num2 = 9223372036854775808L;
for (int i = 0; i < 0x40; i++)
{
if ((keywords & num2) > 0L)
{
list.Add(new EventKeyword((long)num2, this.pmReference));
}
num2 = num2 >> 1;
}
return list;
}
}
///
/// Gets the level.
///
///
/// The level.
///
public EventLevel Level
{
get
{
return new EventLevel(this.level, this.pmReference);
}
}
///
/// Gets the log link.
///
///
/// The log link.
///
public EventLogLink LogLink
{
get
{
return new EventLogLink(this.channelId, this.pmReference);
}
}
///
/// Gets the opcode.
///
///
/// The opcode.
///
public EventOpcode Opcode
{
get
{
return new EventOpcode(this.opcode, this.pmReference);
}
}
///
/// Gets the task.
///
///
/// The task.
///
public EventTask Task
{
get
{
return new EventTask(this.task, this.pmReference);
}
}
///
/// Gets the template.
///
///
/// The template.
///
public string Template
{
get
{
return this.template;
}
}
///
/// Gets the version.
///
///
/// The version.
///
public byte Version
{
get
{
return this.version;
}
}
}
///
///
///
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
internal sealed class EventOpcode
{
// Fields
private bool dataReady;
private string displayName;
private string name;
private ProviderMetadata pmReference;
private object syncObject;
private int value;
// Methods
internal EventOpcode(int value, ProviderMetadata pmReference)
{
this.value = value;
this.pmReference = pmReference;
this.syncObject = new object();
}
internal EventOpcode(string name, int value, string displayName)
{
this.value = value;
this.name = name;
this.displayName = displayName;
this.dataReady = true;
this.syncObject = new object();
}
// Properties
public string DisplayName
{
get
{
this.PrepareData();
return this.displayName;
}
}
public string Name
{
get
{
this.PrepareData();
return this.name;
}
}
public int Value
{
get
{
return this.value;
}
}
internal void PrepareData()
{
lock (this.syncObject)
{
if (!this.dataReady)
{
IEnumerable opcodes = this.pmReference.Opcodes;
this.name = null;
this.displayName = null;
this.dataReady = true;
foreach (EventOpcode opcode in opcodes)
{
if (opcode.Value == this.value)
{
this.name = opcode.Name;
this.displayName = opcode.DisplayName;
this.dataReady = true;
break;
}
}
}
}
}
}
///
/// Contains the value of an event property that is specified by the event provider when the event is published.
///
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public sealed class EventProperty
{
// Fields
private object value;
// Methods
internal EventProperty(object value)
{
this.value = value;
}
// Properties
///
/// Gets the value.
///
///
/// The value.
///
public object Value
{
get
{
return this.value;
}
}
}
///
/// Contains the properties of an event instance for an event that is received from an EventLogReader object. The event properties provide information about the event such as the name of the computer where the event was logged and the time that the event was created.
///
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public class EventRecord : IDisposable
{
private const int SYSTEM_PROPERTY_COUNT = 0x12;
// Fields
private ProviderMetadataCachedInformation cachedMetadataInformation;
private string containerChannel;
[SecurityTreatAsSafe]
private EventLogHandle handle;
private IEnumerable keywordsNames;
private string levelName;
private bool levelNameReady;
private int[] matchedQueryIds;
private string opcodeName;
private bool opcodeNameReady;
private EventLogSession session;
private object syncObject;
private NativeWrapper.SystemProperties systemProperties;
private string taskName;
private bool taskNameReady;
// Methods
[SecurityTreatAsSafe]
internal EventRecord(EventLogHandle handle, EventLogSession session, ProviderMetadataCachedInformation cachedMetadataInfo)
{
this.cachedMetadataInformation = cachedMetadataInfo;
this.handle = handle;
this.session = session;
this.systemProperties = new NativeWrapper.SystemProperties();
this.syncObject = new object();
}
// Properties
///
/// Gets the activity identifier.
///
///
/// The activity identifier.
///
public virtual Guid? ActivityId
{
get
{
this.PrepareSystemData();
return this.systemProperties.ActivityId;
}
}
///
/// Gets the bookmark.
///
///
/// The bookmark.
///
public virtual EventBookmark Bookmark
{
[SecurityTreatAsSafe, SecurityCritical]
get
{
EventLogPermissionHolder.GetEventLogPermission().Demand();
EventLogHandle bookmark = NativeWrapper.EvtCreateBookmark(null);
NativeWrapper.EvtUpdateBookmark(bookmark, this.handle);
return new EventBookmark(NativeWrapper.EvtRenderBookmark(bookmark));
}
}
///
/// Gets the container log.
///
///
/// The container log.
///
public string ContainerLog
{
get
{
if (this.containerChannel != null)
{
return this.containerChannel;
}
lock (this.syncObject)
{
if (this.containerChannel == null)
{
this.containerChannel = (string)NativeWrapper.EvtGetEventInfo(this.Handle, UnsafeNativeMethods.EvtEventPropertyId.EvtEventPath);
}
return this.containerChannel;
}
}
}
///
/// Gets the identifier.
///
///
/// The identifier.
///
public virtual int Id
{
get
{
this.PrepareSystemData();
ushort? id = this.systemProperties.Id;
int? nullable3 = id.HasValue ? new int?(id.GetValueOrDefault()) : null;
if (!nullable3.HasValue)
{
return 0;
}
return this.systemProperties.Id.Value;
}
}
///
/// Gets the keywords.
///
///
/// The keywords.
///
public virtual long? Keywords
{
get
{
this.PrepareSystemData();
ulong? keywords = this.systemProperties.Keywords;
if (!keywords.HasValue)
{
return null;
}
return (long)(keywords.GetValueOrDefault());
}
}
///
/// Gets the keywords display names.
///
///
/// The keywords display names.
///
public virtual IEnumerable KeywordsDisplayNames
{
get
{
if (this.keywordsNames != null)
{
return this.keywordsNames;
}
lock (this.syncObject)
{
if (this.keywordsNames == null)
{
this.keywordsNames = this.cachedMetadataInformation.GetKeywordDisplayNames(this.ProviderName, this.handle);
}
return this.keywordsNames;
}
}
}
///
/// Gets the level.
///
///
/// The level.
///
public virtual byte? Level
{
get
{
this.PrepareSystemData();
return this.systemProperties.Level;
}
}
///
/// Gets the display name of the level.
///
///
/// The display name of the level.
///
public virtual string LevelDisplayName
{
get
{
if (this.levelNameReady)
{
return this.levelName;
}
lock (this.syncObject)
{
if (!this.levelNameReady)
{
this.levelNameReady = true;
this.levelName = this.cachedMetadataInformation.GetLevelDisplayName(this.ProviderName, this.handle);
}
return this.levelName;
}
}
}
///
/// Gets the name of the log.
///
///
/// The name of the log.
///
public virtual string LogName
{
get
{
this.PrepareSystemData();
return this.systemProperties.ChannelName;
}
}
///
/// Gets the name of the machine.
///
///
/// The name of the machine.
///
public virtual string MachineName
{
get
{
this.PrepareSystemData();
return this.systemProperties.ComputerName;
}
}
///
/// Gets the matched query ids.
///
///
/// The matched query ids.
///
public IEnumerable MatchedQueryIds
{
get
{
if (this.matchedQueryIds != null)
{
return this.matchedQueryIds;
}
lock (this.syncObject)
{
if (this.matchedQueryIds == null)
{
this.matchedQueryIds = (int[])NativeWrapper.EvtGetEventInfo(this.Handle, UnsafeNativeMethods.EvtEventPropertyId.EvtEventQueryIDs);
}
return this.matchedQueryIds;
}
}
}
///
/// Gets the opcode.
///
///
/// The opcode.
///
public virtual short? Opcode
{
get
{
this.PrepareSystemData();
byte? opcode = this.systemProperties.Opcode;
ushort? nullable3 = opcode.HasValue ? new ushort?(opcode.GetValueOrDefault()) : null;
if (!nullable3.HasValue)
{
return null;
}
return new short?((short)nullable3.GetValueOrDefault());
}
}
///
/// Gets the display name of the opcode.
///
///
/// The display name of the opcode.
///
public virtual string OpcodeDisplayName
{
get
{
lock (this.syncObject)
{
if (!this.opcodeNameReady)
{
this.opcodeNameReady = true;
this.opcodeName = this.cachedMetadataInformation.GetOpcodeDisplayName(this.ProviderName, this.handle);
}
return this.opcodeName;
}
}
}
///
/// Gets the process identifier.
///
///
/// The process identifier.
///
public virtual int? ProcessId
{
get
{
this.PrepareSystemData();
uint? processId = this.systemProperties.ProcessId;
if (!processId.HasValue)
{
return null;
}
return (int)processId.GetValueOrDefault();
}
}
///
/// Gets the properties.
///
///
/// The properties.
///
public virtual IList Properties
{
get
{
this.session.SetupUserContext();
IList