13 [DesignTimeVisible(
false)]
16 private static class FieldOffsets
18 internal const int LENGTH = 0;
20 internal const int RESERVED = 4;
22 internal const int RECORDNUMBER = 8;
24 internal const int TIMEGENERATED = 12;
26 internal const int TIMEWRITTEN = 16;
28 internal const int EVENTID = 20;
30 internal const int EVENTTYPE = 24;
32 internal const int NUMSTRINGS = 26;
34 internal const int EVENTCATEGORY = 28;
36 internal const int RESERVEDFLAGS = 30;
38 internal const int CLOSINGRECORDNUMBER = 32;
40 internal const int STRINGOFFSET = 36;
42 internal const int USERSIDLENGTH = 40;
44 internal const int USERSIDOFFSET = 44;
46 internal const int DATALENGTH = 48;
48 internal const int DATAOFFSET = 52;
50 internal const int RAWDATA = 56;
53 internal byte[] dataBuf;
55 internal int bufOffset;
57 private EventLogInternal owner;
59 private string category;
61 private string message;
63 private static readonly
DateTime beginningOfTime =
new DateTime(1970, 1, 1, 0, 0, 0);
65 private const int OFFSETFIXUP = 56;
69 [MonitoringDescription(
"LogEntryMachineName")]
75 for (i = bufOffset + 56; CharFrom(dataBuf, i) != 0; i += 2)
79 char c = CharFrom(dataBuf, i);
85 c = CharFrom(dataBuf, i);
93 [MonitoringDescription(
"LogEntryData")]
98 int num = IntFrom(dataBuf, bufOffset + 48);
99 byte[] array =
new byte[num];
100 Array.
Copy(dataBuf, bufOffset + IntFrom(dataBuf, bufOffset + 52), array, 0, num);
107 [MonitoringDescription(
"LogEntryIndex")]
112 return IntFrom(dataBuf, bufOffset + 8);
119 [MonitoringDescription(
"LogEntryCategory")]
124 if (category ==
null)
126 string messageLibraryNames = GetMessageLibraryNames(
"CategoryMessageFile");
127 string text = owner.FormatMessageWrapper(messageLibraryNames, (uint)
CategoryNumber,
null);
143 [MonitoringDescription(
"LogEntryCategoryNumber")]
148 return ShortFrom(dataBuf, bufOffset + 28);
154 [MonitoringDescription(
"LogEntryEventID")]
155 [Obsolete(
"This property has been deprecated. Please use System.Diagnostics.EventLogEntry.InstanceId instead. http://go.microsoft.com/fwlink/?linkid=14202")]
160 return IntFrom(dataBuf, bufOffset + 20) & 0x3FFFFFFF;
166 [MonitoringDescription(
"LogEntryEntryType")]
178 [MonitoringDescription(
"LogEntryMessage")]
179 [Editor(
"System.ComponentModel.Design.BinaryEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
186 string messageLibraryNames = GetMessageLibraryNames(
"EventMessageFile");
187 int num = IntFrom(dataBuf, bufOffset + 20);
188 string text = owner.FormatMessageWrapper(messageLibraryNames, (uint)num,
ReplacementStrings);
193 for (
int i = 0; i < replacementStrings.Length; i++)
197 stringBuilder.
Append(
", ");
199 stringBuilder.
Append(
"'");
200 stringBuilder.
Append(replacementStrings[i]);
201 stringBuilder.
Append(
"'");
217 [MonitoringDescription(
"LogEntrySource")]
223 int num = bufOffset + 56;
224 for (
char c = CharFrom(dataBuf, num); c != 0; c = CharFrom(dataBuf, num))
235 [MonitoringDescription(
"LogEntryReplacementStrings")]
240 string[] array =
new string[ShortFrom(dataBuf, bufOffset + 26)];
242 int num2 = bufOffset + IntFrom(dataBuf, bufOffset + 36);
244 while (num < array.Length)
246 char c = CharFrom(dataBuf, num2);
253 array[num] = stringBuilder.
ToString();
265 [MonitoringDescription(
"LogEntryResourceId")]
271 return (uint)IntFrom(dataBuf, bufOffset + 20);
277 [MonitoringDescription(
"LogEntryTimeGenerated")]
288 [MonitoringDescription(
"LogEntryTimeWritten")]
300 [MonitoringDescription(
"LogEntryUserName")]
305 int num = IntFrom(dataBuf, bufOffset + 40);
310 byte[] array =
new byte[num];
311 Array.
Copy(dataBuf, bufOffset + IntFrom(dataBuf, bufOffset + 44), array, 0, array.Length);
312 int userNameSize = 256;
313 int domainNameSize = 256;
318 if (Microsoft.Win32.UnsafeNativeMethods.LookupAccountSid(
MachineName, array, stringBuilder, ref userNameSize, stringBuilder2, ref domainNameSize, ref eUse) != 0)
321 stringBuilder3.
Append(
"\\");
328 internal EventLogEntry(
byte[] buf,
int offset, EventLogInternal log)
338 dataBuf = (
byte[])info.GetValue(
"DataBuffer", typeof(
byte[]));
339 string @
string = info.GetString(
"LogName");
340 string string2 = info.GetString(
"MachineName");
341 owner =
new EventLogInternal(@
string, string2,
"");
345 private char CharFrom(
byte[] buf,
int offset)
347 return (
char)ShortFrom(buf, offset);
356 if (otherEntry ==
null)
360 int num = IntFrom(dataBuf, bufOffset + 0);
361 int num2 = IntFrom(otherEntry.dataBuf, otherEntry.bufOffset + 0);
366 int num3 = bufOffset;
367 int num4 = bufOffset + num;
368 int num5 = otherEntry.bufOffset;
372 if (dataBuf[num6] != otherEntry.dataBuf[num5])
382 private int IntFrom(
byte[] buf,
int offset)
384 return (-16777216 & (buf[offset + 3] << 24)) | (0xFF0000 & (buf[offset + 2] << 16)) | (0xFF00 & (buf[offset + 1] << 8)) | (0xFF & buf[offset]);
387 internal string ReplaceMessageParameters(
string msg,
string[] insertionStrings)
389 int num = msg.IndexOf(
'%');
395 int length = msg.Length;
397 string messageLibraryNames = GetMessageLibraryNames(
"ParameterMessageFile");
402 for (i = num + 1; i < length &&
char.IsDigit(msg, i); i++)
408 uint.TryParse(msg.Substring(num + 1, i - num - 1), out result);
412 text = owner.FormatMessageWrapper(messageLibraryNames, result, insertionStrings);
418 stringBuilder.
Append(msg, num2, num - num2);
420 stringBuilder.
Append(text);
423 num = msg.IndexOf(
'%', num + 1);
425 if (length - num2 > 0)
427 stringBuilder.
Append(msg, num2, length - num2);
432 private static RegistryKey GetSourceRegKey(
string logName,
string source,
string machineName)
438 registryKey = EventLog.GetEventLogRegKey(machineName, writable:
false);
439 if (registryKey ==
null)
443 registryKey2 = ((logName !=
null) ? registryKey.OpenSubKey(logName, writable:
false) : registryKey.OpenSubKey(
"Application", writable:
false));
444 return registryKey2?.OpenSubKey(source, writable:
false);
448 registryKey?.Close();
449 registryKey2?.Close();
453 private string GetMessageLibraryNames(
string libRegKey)
459 registryKey = GetSourceRegKey(owner.Log,
Source, owner.MachineName);
460 if (registryKey !=
null)
462 text = (string)registryKey.GetValue(libRegKey);
467 registryKey?.Close();
473 if (owner.MachineName !=
".")
475 string[] array = text.Split(
';');
477 for (
int i = 0; i < array.Length; i++)
479 if (array[i].Length >= 2 && array[i][1] ==
':')
481 stringBuilder.
Append(
"\\\\");
482 stringBuilder.
Append(owner.MachineName);
483 stringBuilder.
Append(
"\\");
484 stringBuilder.
Append(array[i][0]);
485 stringBuilder.
Append(
"$");
486 stringBuilder.
Append(array[i], 2, array[i].Length - 2);
487 stringBuilder.
Append(
';');
490 if (stringBuilder.
Length == 0)
499 private short ShortFrom(
byte[] buf,
int offset)
501 return (
short)((0xFF00 & (buf[offset + 1] << 8)) | (0xFF & buf[offset]));
509 int num = IntFrom(dataBuf, bufOffset + 0);
510 byte[] array =
new byte[num];
511 Array.Copy(dataBuf, bufOffset, array, 0, num);
512 info.AddValue(
"DataBuffer", array, typeof(
byte[]));
513 info.AddValue(
"LogName", owner.Log);
514 info.AddValue(
"MachineName", owner.MachineName);
string MachineName
Gets the name of the computer on which this entry was generated.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
static void SuppressFinalize(object obj)
Requests that the common language runtime not call the finalizer for the specified object.
EventLogEntryType
Specifies the event type of an event log entry.
long InstanceId
Gets the resource identifier that designates the message text of the event entry.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Describes the source and destination of a given serialized stream, and provides an additional caller-...
Encapsulates a single record in the event log. This class cannot be inherited.
string Source
Gets the name of the application that generated this event.
DateTime ToLocalTime()
Converts the value of the current T:System.DateTime object to local time.
DateTime TimeGenerated
Gets the local time at which this event was generated.
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
EventLogEntryType EntryType
Gets the event type of this entry.
DateTime TimeWritten
Gets the local time at which this event was written to the log.
string Message
Gets the localized message associated with this event entry.
int Length
Gets or sets the length of the current T:System.Text.StringBuilder object.
Provides the base implementation for the T:System.ComponentModel.IComponent interface and enables obj...
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
string [] ReplacementStrings
Gets the replacement strings associated with the event log entry.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
Controls the system garbage collector, a service that automatically reclaims unused memory.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
short CategoryNumber
Gets the category number of the event log entry.
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
string Category
Gets the text associated with the P:System.Diagnostics.EventLogEntry.CategoryNumber property for this...
Allows an object to control its own serialization and deserialization.
string UserName
Gets the name of the user who is responsible for this event.
int EventID
Gets the application-specific event identifier for the current event entry.
int Index
Gets the index of this entry in the event log.
Specifies that the class can be serialized.
byte [] Data
Gets the binary data associated with the entry.
Provides information about a specific culture (called a locale for unmanaged code development)....
DateTime AddSeconds(double value)
Returns a new T:System.DateTime that adds the specified number of seconds to the value of this instan...
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
bool Equals(EventLogEntry otherEntry)
Performs a comparison between two event log entries.