mscorlib(4.0.0.0) API with additions
EventLog.cs
1 using Microsoft.Win32;
2 using Microsoft.Win32.SafeHandles;
3 using System.Collections;
6 using System.IO;
9 using System.Security;
11 using System.Text;
12 using System.Threading;
13 
14 namespace System.Diagnostics
15 {
17  [DefaultEvent("EntryWritten")]
18  [InstallerType("System.Diagnostics.EventLogInstaller, System.Configuration.Install, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
19  [MonitoringDescription("EventLogDesc")]
21  {
22  private const string EventLogKey = "SYSTEM\\CurrentControlSet\\Services\\EventLog";
23 
24  internal const string DllName = "EventLogMessages.dll";
25 
26  private const string eventLogMutexName = "netfxeventlog.1.0";
27 
28  private const int DefaultMaxSize = 524288;
29 
30  private const int DefaultRetention = 604800;
31 
32  private const int SecondsPerDay = 86400;
33 
34  private EventLogInternal m_underlyingEventLog;
35 
36  private static volatile bool s_CheckedOsVersion;
37 
38  private static volatile bool s_SkipRegPatch;
39 
40  private static bool SkipRegPatch
41  {
42  get
43  {
44  if (!s_CheckedOsVersion)
45  {
47  s_SkipRegPatch = (oSVersion.Platform == PlatformID.Win32NT && oSVersion.Version.Major > 5);
48  s_CheckedOsVersion = true;
49  }
50  return s_SkipRegPatch;
51  }
52  }
53 
56  [Browsable(false)]
58  [MonitoringDescription("LogEntries")]
60  {
61  get
62  {
63  return m_underlyingEventLog.Entries;
64  }
65  }
66 
70  [Browsable(false)]
71  public string LogDisplayName
72  {
73  get
74  {
75  return m_underlyingEventLog.LogDisplayName;
76  }
77  }
78 
81  [TypeConverter("System.Diagnostics.Design.LogConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
82  [ReadOnly(true)]
83  [MonitoringDescription("LogLog")]
84  [DefaultValue("")]
85  [SettingsBindable(true)]
86  public string Log
87  {
88  get
89  {
90  return m_underlyingEventLog.Log;
91  }
92  set
93  {
94  EventLogInternal eventLogInternal = new EventLogInternal(value, m_underlyingEventLog.MachineName, m_underlyingEventLog.Source, this);
95  EventLogInternal underlyingEventLog = m_underlyingEventLog;
96  new EventLogPermission(EventLogPermissionAccess.Write, underlyingEventLog.machineName).Assert();
97  if (underlyingEventLog.EnableRaisingEvents)
98  {
99  eventLogInternal.onEntryWrittenHandler = underlyingEventLog.onEntryWrittenHandler;
100  eventLogInternal.EnableRaisingEvents = true;
101  }
102  m_underlyingEventLog = eventLogInternal;
103  underlyingEventLog.Close();
104  }
105  }
106 
110  [ReadOnly(true)]
111  [MonitoringDescription("LogMachineName")]
112  [DefaultValue(".")]
113  [SettingsBindable(true)]
114  public string MachineName
115  {
116  get
117  {
118  return m_underlyingEventLog.MachineName;
119  }
120  set
121  {
122  EventLogInternal eventLogInternal = new EventLogInternal(m_underlyingEventLog.logName, value, m_underlyingEventLog.sourceName, this);
123  EventLogInternal underlyingEventLog = m_underlyingEventLog;
124  new EventLogPermission(EventLogPermissionAccess.Write, underlyingEventLog.machineName).Assert();
125  if (underlyingEventLog.EnableRaisingEvents)
126  {
127  eventLogInternal.onEntryWrittenHandler = underlyingEventLog.onEntryWrittenHandler;
128  eventLogInternal.EnableRaisingEvents = true;
129  }
130  m_underlyingEventLog = eventLogInternal;
131  underlyingEventLog.Close();
132  }
133  }
134 
140  [Browsable(false)]
141  [ComVisible(false)]
142  public long MaximumKilobytes
143  {
144  get
145  {
146  return m_underlyingEventLog.MaximumKilobytes;
147  }
148  set
149  {
150  m_underlyingEventLog.MaximumKilobytes = value;
151  }
152  }
153 
156  [Browsable(false)]
157  [ComVisible(false)]
159  {
160  get
161  {
162  return m_underlyingEventLog.OverflowAction;
163  }
164  }
165 
168  [Browsable(false)]
169  [ComVisible(false)]
170  public int MinimumRetentionDays
171  {
172  get
173  {
174  return m_underlyingEventLog.MinimumRetentionDays;
175  }
176  }
177 
178  internal bool ComponentDesignMode => base.DesignMode;
179 
184  [Browsable(false)]
185  [MonitoringDescription("LogMonitoring")]
186  [DefaultValue(false)]
187  public bool EnableRaisingEvents
188  {
189  get
190  {
191  return m_underlyingEventLog.EnableRaisingEvents;
192  }
193  set
194  {
195  m_underlyingEventLog.EnableRaisingEvents = value;
196  }
197  }
198 
201  [Browsable(false)]
202  [DefaultValue(null)]
203  [MonitoringDescription("LogSynchronizingObject")]
205  {
206  [HostProtection(SecurityAction.LinkDemand, Synchronization = true)]
207  get
208  {
209  return m_underlyingEventLog.SynchronizingObject;
210  }
211  set
212  {
213  m_underlyingEventLog.SynchronizingObject = value;
214  }
215  }
216 
220  [ReadOnly(true)]
221  [TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
222  [MonitoringDescription("LogSource")]
223  [DefaultValue("")]
224  [SettingsBindable(true)]
225  public string Source
226  {
227  get
228  {
229  return m_underlyingEventLog.Source;
230  }
231  set
232  {
233  EventLogInternal eventLogInternal = new EventLogInternal(m_underlyingEventLog.Log, m_underlyingEventLog.MachineName, CheckAndNormalizeSourceName(value), this);
234  EventLogInternal underlyingEventLog = m_underlyingEventLog;
235  new EventLogPermission(EventLogPermissionAccess.Write, underlyingEventLog.machineName).Assert();
236  if (underlyingEventLog.EnableRaisingEvents)
237  {
238  eventLogInternal.onEntryWrittenHandler = underlyingEventLog.onEntryWrittenHandler;
239  eventLogInternal.EnableRaisingEvents = true;
240  }
241  m_underlyingEventLog = eventLogInternal;
242  underlyingEventLog.Close();
243  }
244  }
245 
247  [MonitoringDescription("LogEntryWritten")]
249  {
250  add
251  {
252  m_underlyingEventLog.EntryWritten += value;
253  }
254  remove
255  {
256  m_underlyingEventLog.EntryWritten -= value;
257  }
258  }
259 
260  internal static PermissionSet _UnsafeGetAssertPermSet()
261  {
262  PermissionSet permissionSet = new PermissionSet(PermissionState.None);
263  RegistryPermission perm = new RegistryPermission(PermissionState.Unrestricted);
264  permissionSet.AddPermission(perm);
266  permissionSet.AddPermission(perm2);
268  permissionSet.AddPermission(perm3);
269  return permissionSet;
270  }
271 
273  public EventLog()
274  : this("", ".", "")
275  {
276  }
277 
282  public EventLog(string logName)
283  : this(logName, ".", "")
284  {
285  }
286 
292  public EventLog(string logName, string machineName)
293  : this(logName, machineName, "")
294  {
295  }
296 
303  public EventLog(string logName, string machineName, string source)
304  {
305  m_underlyingEventLog = new EventLogInternal(logName, machineName, source, this);
306  }
307 
308  internal object ComponentGetService(Type service)
309  {
310  return GetService(service);
311  }
312 
316  public void BeginInit()
317  {
318  m_underlyingEventLog.BeginInit();
319  }
320 
325  public void Clear()
326  {
327  m_underlyingEventLog.Clear();
328  }
329 
332  public void Close()
333  {
334  m_underlyingEventLog.Close();
335  }
336 
345  public static void CreateEventSource(string source, string logName)
346  {
347  CreateEventSource(new EventSourceCreationData(source, logName, "."));
348  }
349 
359  [Obsolete("This method has been deprecated. Please use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead. http://go.microsoft.com/fwlink/?linkid=14202")]
360  public static void CreateEventSource(string source, string logName, string machineName)
361  {
362  CreateEventSource(new EventSourceCreationData(source, logName, machineName));
363  }
364 
371  public static void CreateEventSource(EventSourceCreationData sourceData)
372  {
373  if (sourceData == null)
374  {
375  throw new ArgumentNullException("sourceData");
376  }
377  string text = sourceData.LogName;
378  string source = sourceData.Source;
379  string machineName = sourceData.MachineName;
380  if (!SyntaxCheck.CheckMachineName(machineName))
381  {
382  throw new ArgumentException(SR.GetString("InvalidParameter", "machineName", machineName));
383  }
384  if (text == null || text.Length == 0)
385  {
386  text = "Application";
387  }
388  if (!ValidLogName(text, ignoreEmpty: false))
389  {
390  throw new ArgumentException(SR.GetString("BadLogName"));
391  }
392  if (source == null || source.Length == 0)
393  {
394  throw new ArgumentException(SR.GetString("MissingParameter", "source"));
395  }
396  if (source.Length + "SYSTEM\\CurrentControlSet\\Services\\EventLog".Length > 254)
397  {
398  throw new ArgumentException(SR.GetString("ParameterTooLong", "source", 254 - "SYSTEM\\CurrentControlSet\\Services\\EventLog".Length));
399  }
400  EventLogPermission eventLogPermission = new EventLogPermission(EventLogPermissionAccess.Administer, machineName);
401  eventLogPermission.Demand();
402  Mutex mutex = null;
404  try
405  {
406  SharedUtils.EnterMutex("netfxeventlog.1.0", ref mutex);
407  if (SourceExists(source, machineName, wantToCreate: true))
408  {
409  if (".".Equals(machineName))
410  {
411  throw new ArgumentException(SR.GetString("LocalSourceAlreadyExists", source));
412  }
413  throw new ArgumentException(SR.GetString("SourceAlreadyExists", source, machineName));
414  }
415  PermissionSet permissionSet = _UnsafeGetAssertPermSet();
416  permissionSet.Assert();
417  RegistryKey registryKey = null;
418  RegistryKey registryKey2 = null;
419  RegistryKey registryKey3 = null;
420  RegistryKey registryKey4 = null;
421  RegistryKey registryKey5 = null;
422  try
423  {
424  registryKey = ((!(machineName == ".")) ? RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, machineName) : Registry.LocalMachine);
425  registryKey2 = registryKey.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\EventLog", writable: true);
426  if (registryKey2 == null)
427  {
428  if (!".".Equals(machineName))
429  {
430  throw new InvalidOperationException(SR.GetString("RegKeyMissing", "SYSTEM\\CurrentControlSet\\Services\\EventLog", text, source, machineName));
431  }
432  throw new InvalidOperationException(SR.GetString("LocalRegKeyMissing", "SYSTEM\\CurrentControlSet\\Services\\EventLog", text, source));
433  }
434  registryKey3 = registryKey2.OpenSubKey(text, writable: true);
435  if (registryKey3 == null && text.Length >= 8)
436  {
437  string strA = text.Substring(0, 8);
438  if (string.Compare(strA, "AppEvent", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(strA, "SecEvent", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(strA, "SysEvent", StringComparison.OrdinalIgnoreCase) == 0)
439  {
440  throw new ArgumentException(SR.GetString("InvalidCustomerLogName", text));
441  }
442  string text2 = FindSame8FirstCharsLog(registryKey2, text);
443  if (text2 != null)
444  {
445  throw new ArgumentException(SR.GetString("DuplicateLogName", text, text2));
446  }
447  }
448  bool flag = registryKey3 == null;
449  if (flag)
450  {
451  if (SourceExists(text, machineName, wantToCreate: true))
452  {
453  if (".".Equals(machineName))
454  {
455  throw new ArgumentException(SR.GetString("LocalLogAlreadyExistsAsSource", text));
456  }
457  throw new ArgumentException(SR.GetString("LogAlreadyExistsAsSource", text, machineName));
458  }
459  registryKey3 = registryKey2.CreateSubKey(text);
460  if (!SkipRegPatch)
461  {
462  registryKey3.SetValue("Sources", new string[2]
463  {
464  text,
465  source
466  }, RegistryValueKind.MultiString);
467  }
468  SetSpecialLogRegValues(registryKey3, text);
469  registryKey4 = registryKey3.CreateSubKey(text);
470  SetSpecialSourceRegValues(registryKey4, sourceData);
471  }
472  if (text != source)
473  {
474  if (!flag)
475  {
476  SetSpecialLogRegValues(registryKey3, text);
477  if (!SkipRegPatch)
478  {
479  string[] array = registryKey3.GetValue("Sources") as string[];
480  if (array == null)
481  {
482  registryKey3.SetValue("Sources", new string[2]
483  {
484  text,
485  source
486  }, RegistryValueKind.MultiString);
487  }
488  else if (Array.IndexOf(array, source) == -1)
489  {
490  string[] array2 = new string[array.Length + 1];
491  Array.Copy(array, array2, array.Length);
492  array2[array.Length] = source;
493  registryKey3.SetValue("Sources", array2, RegistryValueKind.MultiString);
494  }
495  }
496  }
497  registryKey5 = registryKey3.CreateSubKey(source);
498  SetSpecialSourceRegValues(registryKey5, sourceData);
499  }
500  }
501  finally
502  {
503  registryKey?.Close();
504  registryKey2?.Close();
505  if (registryKey3 != null)
506  {
507  registryKey3.Flush();
508  registryKey3.Close();
509  }
510  if (registryKey4 != null)
511  {
512  registryKey4.Flush();
513  registryKey4.Close();
514  }
515  if (registryKey5 != null)
516  {
517  registryKey5.Flush();
518  registryKey5.Close();
519  }
521  }
522  }
523  finally
524  {
525  if (mutex != null)
526  {
527  mutex.ReleaseMutex();
528  mutex.Close();
529  }
530  }
531  }
532 
539  public static void Delete(string logName)
540  {
541  Delete(logName, ".");
542  }
543 
552  public static void Delete(string logName, string machineName)
553  {
554  if (!SyntaxCheck.CheckMachineName(machineName))
555  {
556  throw new ArgumentException(SR.GetString("InvalidParameterFormat", "machineName"));
557  }
558  if (logName == null || logName.Length == 0)
559  {
560  throw new ArgumentException(SR.GetString("NoLogName"));
561  }
562  if (!ValidLogName(logName, ignoreEmpty: false))
563  {
564  throw new InvalidOperationException(SR.GetString("BadLogName"));
565  }
566  EventLogPermission eventLogPermission = new EventLogPermission(EventLogPermissionAccess.Administer, machineName);
567  eventLogPermission.Demand();
568  SharedUtils.CheckEnvironment();
569  PermissionSet permissionSet = _UnsafeGetAssertPermSet();
570  permissionSet.Assert();
571  RegistryKey registryKey = null;
572  Mutex mutex = null;
574  try
575  {
576  SharedUtils.EnterMutex("netfxeventlog.1.0", ref mutex);
577  try
578  {
579  registryKey = GetEventLogRegKey(machineName, writable: true);
580  if (registryKey == null)
581  {
582  throw new InvalidOperationException(SR.GetString("RegKeyNoAccess", "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\EventLog", machineName));
583  }
584  using (RegistryKey registryKey2 = registryKey.OpenSubKey(logName))
585  {
586  if (registryKey2 == null)
587  {
588  throw new InvalidOperationException(SR.GetString("MissingLog", logName, machineName));
589  }
590  EventLog eventLog = new EventLog(logName, machineName);
591  try
592  {
593  eventLog.Clear();
594  }
595  finally
596  {
597  eventLog.Close();
598  }
599  string text = null;
600  try
601  {
602  text = (string)registryKey2.GetValue("File");
603  }
604  catch
605  {
606  }
607  if (text != null)
608  {
609  try
610  {
611  File.Delete(text);
612  }
613  catch
614  {
615  }
616  }
617  }
618  registryKey.DeleteSubKeyTree(logName);
619  }
620  finally
621  {
622  registryKey?.Close();
624  }
625  }
626  finally
627  {
628  mutex?.ReleaseMutex();
629  }
630  }
631 
635  public static void DeleteEventSource(string source)
636  {
637  DeleteEventSource(source, ".");
638  }
639 
646  public static void DeleteEventSource(string source, string machineName)
647  {
648  if (!SyntaxCheck.CheckMachineName(machineName))
649  {
650  throw new ArgumentException(SR.GetString("InvalidParameter", "machineName", machineName));
651  }
652  EventLogPermission eventLogPermission = new EventLogPermission(EventLogPermissionAccess.Administer, machineName);
653  eventLogPermission.Demand();
654  SharedUtils.CheckEnvironment();
655  PermissionSet permissionSet = _UnsafeGetAssertPermSet();
656  permissionSet.Assert();
657  Mutex mutex = null;
659  try
660  {
661  SharedUtils.EnterMutex("netfxeventlog.1.0", ref mutex);
662  RegistryKey registryKey = null;
663  using (registryKey = FindSourceRegistration(source, machineName, readOnly: true))
664  {
665  if (registryKey == null)
666  {
667  if (machineName == null)
668  {
669  throw new ArgumentException(SR.GetString("LocalSourceNotRegistered", source));
670  }
671  throw new ArgumentException(SR.GetString("SourceNotRegistered", source, machineName, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\EventLog"));
672  }
673  string name = registryKey.Name;
674  int num = name.LastIndexOf('\\');
675  if (string.Compare(name, num + 1, source, 0, name.Length - num, StringComparison.Ordinal) == 0)
676  {
677  throw new InvalidOperationException(SR.GetString("CannotDeleteEqualSource", source));
678  }
679  }
680  try
681  {
682  registryKey = FindSourceRegistration(source, machineName, readOnly: false);
683  registryKey.DeleteSubKeyTree(source);
684  if (!SkipRegPatch)
685  {
686  string[] array = (string[])registryKey.GetValue("Sources");
687  ArrayList arrayList = new ArrayList(array.Length - 1);
688  for (int i = 0; i < array.Length; i++)
689  {
690  if (array[i] != source)
691  {
692  arrayList.Add(array[i]);
693  }
694  }
695  string[] array2 = new string[arrayList.Count];
696  arrayList.CopyTo(array2);
697  registryKey.SetValue("Sources", array2, RegistryValueKind.MultiString);
698  }
699  }
700  finally
701  {
702  if (registryKey != null)
703  {
704  registryKey.Flush();
705  registryKey.Close();
706  }
708  }
709  }
710  finally
711  {
712  mutex?.ReleaseMutex();
713  }
714  }
715 
719  protected override void Dispose(bool disposing)
720  {
721  if (m_underlyingEventLog != null)
722  {
723  m_underlyingEventLog.Dispose(disposing);
724  }
725  base.Dispose(disposing);
726  }
727 
729  public void EndInit()
730  {
731  m_underlyingEventLog.EndInit();
732  }
733 
739  public static bool Exists(string logName)
740  {
741  return Exists(logName, ".");
742  }
743 
750  public static bool Exists(string logName, string machineName)
751  {
752  if (!SyntaxCheck.CheckMachineName(machineName))
753  {
754  throw new ArgumentException(SR.GetString("InvalidParameterFormat", "machineName"));
755  }
756  EventLogPermission eventLogPermission = new EventLogPermission(EventLogPermissionAccess.Administer, machineName);
757  eventLogPermission.Demand();
758  if (logName == null || logName.Length == 0)
759  {
760  return false;
761  }
762  SharedUtils.CheckEnvironment();
763  PermissionSet permissionSet = _UnsafeGetAssertPermSet();
764  permissionSet.Assert();
765  RegistryKey registryKey = null;
766  RegistryKey registryKey2 = null;
767  try
768  {
769  registryKey = GetEventLogRegKey(machineName, writable: false);
770  if (registryKey == null)
771  {
772  return false;
773  }
774  registryKey2 = registryKey.OpenSubKey(logName, writable: false);
775  return registryKey2 != null;
776  }
777  finally
778  {
779  registryKey?.Close();
780  registryKey2?.Close();
782  }
783  }
784 
785  private static string FindSame8FirstCharsLog(RegistryKey keyParent, string logName)
786  {
787  string strB = logName.Substring(0, 8);
788  string[] subKeyNames = keyParent.GetSubKeyNames();
789  foreach (string text in subKeyNames)
790  {
791  if (text.Length >= 8 && string.Compare(text.Substring(0, 8), strB, StringComparison.OrdinalIgnoreCase) == 0)
792  {
793  return text;
794  }
795  }
796  return null;
797  }
798 
799  private static RegistryKey FindSourceRegistration(string source, string machineName, bool readOnly)
800  {
801  return FindSourceRegistration(source, machineName, readOnly, wantToCreate: false);
802  }
803 
804  private static RegistryKey FindSourceRegistration(string source, string machineName, bool readOnly, bool wantToCreate)
805  {
806  if (source != null && source.Length != 0)
807  {
808  SharedUtils.CheckEnvironment();
809  PermissionSet permissionSet = _UnsafeGetAssertPermSet();
810  permissionSet.Assert();
811  RegistryKey registryKey = null;
812  try
813  {
814  registryKey = GetEventLogRegKey(machineName, !readOnly);
815  if (registryKey == null)
816  {
817  return null;
818  }
819  StringBuilder stringBuilder = null;
820  string[] subKeyNames = registryKey.GetSubKeyNames();
821  for (int i = 0; i < subKeyNames.Length; i++)
822  {
823  RegistryKey registryKey2 = null;
824  try
825  {
826  RegistryKey registryKey3 = registryKey.OpenSubKey(subKeyNames[i], !readOnly);
827  if (registryKey3 != null)
828  {
829  registryKey2 = registryKey3.OpenSubKey(source, !readOnly);
830  if (registryKey2 != null)
831  {
832  return registryKey3;
833  }
834  registryKey3.Close();
835  }
836  }
837  catch (UnauthorizedAccessException)
838  {
839  if (stringBuilder == null)
840  {
841  stringBuilder = new StringBuilder(subKeyNames[i]);
842  }
843  else
844  {
845  stringBuilder.Append(", ");
846  stringBuilder.Append(subKeyNames[i]);
847  }
848  }
849  catch (SecurityException)
850  {
851  if (stringBuilder == null)
852  {
853  stringBuilder = new StringBuilder(subKeyNames[i]);
854  }
855  else
856  {
857  stringBuilder.Append(", ");
858  stringBuilder.Append(subKeyNames[i]);
859  }
860  }
861  finally
862  {
863  registryKey2?.Close();
864  }
865  }
866  if (stringBuilder != null)
867  {
868  throw new SecurityException(SR.GetString(wantToCreate ? "SomeLogsInaccessibleToCreate" : "SomeLogsInaccessible", stringBuilder.ToString()));
869  }
870  }
871  finally
872  {
873  registryKey?.Close();
875  }
876  }
877  return null;
878  }
879 
883  public static EventLog[] GetEventLogs()
884  {
885  return GetEventLogs(".");
886  }
887 
893  public static EventLog[] GetEventLogs(string machineName)
894  {
895  if (!SyntaxCheck.CheckMachineName(machineName))
896  {
897  throw new ArgumentException(SR.GetString("InvalidParameter", "machineName", machineName));
898  }
899  EventLogPermission eventLogPermission = new EventLogPermission(EventLogPermissionAccess.Administer, machineName);
900  eventLogPermission.Demand();
901  SharedUtils.CheckEnvironment();
902  string[] array = new string[0];
903  PermissionSet permissionSet = _UnsafeGetAssertPermSet();
904  permissionSet.Assert();
905  RegistryKey registryKey = null;
906  try
907  {
908  registryKey = GetEventLogRegKey(machineName, writable: false);
909  if (registryKey == null)
910  {
911  throw new InvalidOperationException(SR.GetString("RegKeyMissingShort", "SYSTEM\\CurrentControlSet\\Services\\EventLog", machineName));
912  }
913  array = registryKey.GetSubKeyNames();
914  }
915  finally
916  {
917  registryKey?.Close();
919  }
920  EventLog[] array2 = new EventLog[array.Length];
921  for (int i = 0; i < array.Length; i++)
922  {
923  EventLog eventLog = array2[i] = new EventLog(array[i], machineName);
924  }
925  return array2;
926  }
927 
928  internal static RegistryKey GetEventLogRegKey(string machine, bool writable)
929  {
930  RegistryKey registryKey = null;
931  try
932  {
933  registryKey = ((!machine.Equals(".")) ? RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, machine) : Registry.LocalMachine);
934  if (registryKey != null)
935  {
936  return registryKey.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\EventLog", writable);
937  }
938  }
939  finally
940  {
941  registryKey?.Close();
942  }
943  return null;
944  }
945 
946  internal static string GetDllPath(string machineName)
947  {
948  return Path.Combine(SharedUtils.GetLatestBuildDllDirectory(machineName), "EventLogMessages.dll");
949  }
950 
957  public static bool SourceExists(string source)
958  {
959  return SourceExists(source, ".");
960  }
961 
971  public static bool SourceExists(string source, string machineName)
972  {
973  return SourceExists(source, machineName, wantToCreate: false);
974  }
975 
976  internal static bool SourceExists(string source, string machineName, bool wantToCreate)
977  {
978  if (!SyntaxCheck.CheckMachineName(machineName))
979  {
980  throw new ArgumentException(SR.GetString("InvalidParameter", "machineName", machineName));
981  }
982  EventLogPermission eventLogPermission = new EventLogPermission(EventLogPermissionAccess.Write, machineName);
983  eventLogPermission.Demand();
984  using (RegistryKey registryKey = FindSourceRegistration(source, machineName, readOnly: true, wantToCreate))
985  {
986  return registryKey != null;
987  }
988  }
989 
994  public static string LogNameFromSourceName(string source, string machineName)
995  {
996  EventLogPermission eventLogPermission = new EventLogPermission(EventLogPermissionAccess.Administer, machineName);
997  eventLogPermission.Demand();
998  return _InternalLogNameFromSourceName(source, machineName);
999  }
1000 
1001  internal static string _InternalLogNameFromSourceName(string source, string machineName)
1002  {
1003  using (RegistryKey registryKey = FindSourceRegistration(source, machineName, readOnly: true))
1004  {
1005  if (registryKey == null)
1006  {
1007  return "";
1008  }
1009  string name = registryKey.Name;
1010  int num = name.LastIndexOf('\\');
1011  return name.Substring(num + 1);
1012  }
1013  }
1014 
1023  [ComVisible(false)]
1024  public void ModifyOverflowPolicy(OverflowAction action, int retentionDays)
1025  {
1026  m_underlyingEventLog.ModifyOverflowPolicy(action, retentionDays);
1027  }
1028 
1035  [ComVisible(false)]
1036  public void RegisterDisplayName(string resourceFile, long resourceId)
1037  {
1038  m_underlyingEventLog.RegisterDisplayName(resourceFile, resourceId);
1039  }
1040 
1041  private static void SetSpecialLogRegValues(RegistryKey logKey, string logName)
1042  {
1043  if (logKey.GetValue("MaxSize") == null)
1044  {
1045  logKey.SetValue("MaxSize", 524288, RegistryValueKind.DWord);
1046  }
1047  if (logKey.GetValue("AutoBackupLogFiles") == null)
1048  {
1049  logKey.SetValue("AutoBackupLogFiles", 0, RegistryValueKind.DWord);
1050  }
1051  if (!SkipRegPatch)
1052  {
1053  if (logKey.GetValue("Retention") == null)
1054  {
1055  logKey.SetValue("Retention", 604800, RegistryValueKind.DWord);
1056  }
1057  if (logKey.GetValue("File") == null)
1058  {
1059  string value = (logName.Length <= 8) ? ("%SystemRoot%\\System32\\config\\" + logName + ".evt") : ("%SystemRoot%\\System32\\config\\" + logName.Substring(0, 8) + ".evt");
1060  logKey.SetValue("File", value, RegistryValueKind.ExpandString);
1061  }
1062  }
1063  }
1064 
1065  private static void SetSpecialSourceRegValues(RegistryKey sourceLogKey, EventSourceCreationData sourceData)
1066  {
1067  if (string.IsNullOrEmpty(sourceData.MessageResourceFile))
1068  {
1069  sourceLogKey.SetValue("EventMessageFile", GetDllPath(sourceData.MachineName), RegistryValueKind.ExpandString);
1070  }
1071  else
1072  {
1073  sourceLogKey.SetValue("EventMessageFile", FixupPath(sourceData.MessageResourceFile), RegistryValueKind.ExpandString);
1074  }
1075  if (!string.IsNullOrEmpty(sourceData.ParameterResourceFile))
1076  {
1077  sourceLogKey.SetValue("ParameterMessageFile", FixupPath(sourceData.ParameterResourceFile), RegistryValueKind.ExpandString);
1078  }
1079  if (!string.IsNullOrEmpty(sourceData.CategoryResourceFile))
1080  {
1081  sourceLogKey.SetValue("CategoryMessageFile", FixupPath(sourceData.CategoryResourceFile), RegistryValueKind.ExpandString);
1082  sourceLogKey.SetValue("CategoryCount", sourceData.CategoryCount, RegistryValueKind.DWord);
1083  }
1084  }
1085 
1086  private static string FixupPath(string path)
1087  {
1088  if (path[0] == '%')
1089  {
1090  return path;
1091  }
1092  return Path.GetFullPath(path);
1093  }
1094 
1095  internal static string TryFormatMessage(Microsoft.Win32.SafeHandles.SafeLibraryHandle hModule, uint messageNum, string[] insertionStrings)
1096  {
1097  if (insertionStrings.Length == 0)
1098  {
1099  return UnsafeTryFormatMessage(hModule, messageNum, insertionStrings);
1100  }
1101  string text = UnsafeTryFormatMessage(hModule, messageNum, new string[0]);
1102  if (text == null)
1103  {
1104  return null;
1105  }
1106  int num = 0;
1107  for (int i = 0; i < text.Length; i++)
1108  {
1109  if (text[i] != '%' || text.Length <= i + 1)
1110  {
1111  continue;
1112  }
1113  StringBuilder stringBuilder = new StringBuilder();
1114  for (; i + 1 < text.Length && char.IsDigit(text[i + 1]); i++)
1115  {
1116  stringBuilder.Append(text[i + 1]);
1117  }
1118  i++;
1119  if (stringBuilder.Length > 0)
1120  {
1121  int result = -1;
1122  if (int.TryParse(stringBuilder.ToString(), NumberStyles.None, CultureInfo.InvariantCulture, out result))
1123  {
1124  num = Math.Max(num, result);
1125  }
1126  }
1127  }
1128  if (num > insertionStrings.Length)
1129  {
1130  string[] array = new string[num];
1131  Array.Copy(insertionStrings, array, insertionStrings.Length);
1132  for (int j = insertionStrings.Length; j < array.Length; j++)
1133  {
1134  array[j] = "%" + (j + 1);
1135  }
1136  insertionStrings = array;
1137  }
1138  return UnsafeTryFormatMessage(hModule, messageNum, insertionStrings);
1139  }
1140 
1141  internal static string UnsafeTryFormatMessage(Microsoft.Win32.SafeHandles.SafeLibraryHandle hModule, uint messageNum, string[] insertionStrings)
1142  {
1143  string text = null;
1144  int num = 0;
1145  StringBuilder stringBuilder = new StringBuilder(1024);
1146  int num2 = 10240;
1147  IntPtr[] array = new IntPtr[insertionStrings.Length];
1148  GCHandle[] array2 = new GCHandle[insertionStrings.Length];
1149  GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
1150  if (insertionStrings.Length == 0)
1151  {
1152  num2 |= 0x200;
1153  }
1154  try
1155  {
1156  for (int i = 0; i < array2.Length; i++)
1157  {
1158  array2[i] = GCHandle.Alloc(insertionStrings[i], GCHandleType.Pinned);
1159  array[i] = array2[i].AddrOfPinnedObject();
1160  }
1161  int num3 = 122;
1162  while (num == 0 && num3 == 122)
1163  {
1164  num = Microsoft.Win32.SafeNativeMethods.FormatMessage(num2, hModule, messageNum, 0, stringBuilder, stringBuilder.Capacity, array);
1165  if (num == 0)
1166  {
1167  num3 = Marshal.GetLastWin32Error();
1168  if (num3 == 122)
1169  {
1170  stringBuilder.Capacity *= 2;
1171  }
1172  }
1173  }
1174  }
1175  catch
1176  {
1177  num = 0;
1178  }
1179  finally
1180  {
1181  for (int j = 0; j < array2.Length; j++)
1182  {
1183  if (array2[j].IsAllocated)
1184  {
1185  array2[j].Free();
1186  }
1187  }
1188  gCHandle.Free();
1189  }
1190  if (num > 0)
1191  {
1192  text = stringBuilder.ToString();
1193  if (text.Length > 1 && text[text.Length - 1] == '\n')
1194  {
1195  text = text.Substring(0, text.Length - 2);
1196  }
1197  }
1198  return text;
1199  }
1200 
1201  private static bool CharIsPrintable(char c)
1202  {
1203  UnicodeCategory unicodeCategory = char.GetUnicodeCategory(c);
1204  if (unicodeCategory == UnicodeCategory.Control && unicodeCategory != UnicodeCategory.Format && unicodeCategory != UnicodeCategory.LineSeparator && unicodeCategory != UnicodeCategory.ParagraphSeparator)
1205  {
1206  return unicodeCategory == UnicodeCategory.OtherNotAssigned;
1207  }
1208  return true;
1209  }
1210 
1211  internal static bool ValidLogName(string logName, bool ignoreEmpty)
1212  {
1213  if (logName.Length == 0 && !ignoreEmpty)
1214  {
1215  return false;
1216  }
1217  foreach (char c in logName)
1218  {
1219  if (!CharIsPrintable(c) || c == '\\' || c == '*' || c == '?')
1220  {
1221  return false;
1222  }
1223  }
1224  return true;
1225  }
1226 
1232  public void WriteEntry(string message)
1233  {
1234  WriteEntry(message, EventLogEntryType.Information, 0, 0, null);
1235  }
1236 
1243  public static void WriteEntry(string source, string message)
1244  {
1245  WriteEntry(source, message, EventLogEntryType.Information, 0, 0, null);
1246  }
1247 
1256  public void WriteEntry(string message, EventLogEntryType type)
1257  {
1258  WriteEntry(message, type, 0, 0, null);
1259  }
1260 
1270  public static void WriteEntry(string source, string message, EventLogEntryType type)
1271  {
1272  WriteEntry(source, message, type, 0, 0, null);
1273  }
1274 
1285  public void WriteEntry(string message, EventLogEntryType type, int eventID)
1286  {
1287  WriteEntry(message, type, eventID, 0, null);
1288  }
1289 
1301  public static void WriteEntry(string source, string message, EventLogEntryType type, int eventID)
1302  {
1303  WriteEntry(source, message, type, eventID, 0, null);
1304  }
1305 
1317  public void WriteEntry(string message, EventLogEntryType type, int eventID, short category)
1318  {
1319  WriteEntry(message, type, eventID, category, null);
1320  }
1321 
1334  public static void WriteEntry(string source, string message, EventLogEntryType type, int eventID, short category)
1335  {
1336  WriteEntry(source, message, type, eventID, category, null);
1337  }
1338 
1352  public static void WriteEntry(string source, string message, EventLogEntryType type, int eventID, short category, byte[] rawData)
1353  {
1354  using (EventLogInternal eventLogInternal = new EventLogInternal("", ".", CheckAndNormalizeSourceName(source)))
1355  {
1356  eventLogInternal.WriteEntry(message, type, eventID, category, rawData);
1357  }
1358  }
1359 
1372  public void WriteEntry(string message, EventLogEntryType type, int eventID, short category, byte[] rawData)
1373  {
1374  m_underlyingEventLog.WriteEntry(message, type, eventID, category, rawData);
1375  }
1376 
1387  [ComVisible(false)]
1388  public void WriteEvent(EventInstance instance, params object[] values)
1389  {
1390  WriteEvent(instance, null, values);
1391  }
1392 
1404  [ComVisible(false)]
1405  public void WriteEvent(EventInstance instance, byte[] data, params object[] values)
1406  {
1407  m_underlyingEventLog.WriteEvent(instance, data, values);
1408  }
1409 
1421  public static void WriteEvent(string source, EventInstance instance, params object[] values)
1422  {
1423  using (EventLogInternal eventLogInternal = new EventLogInternal("", ".", CheckAndNormalizeSourceName(source)))
1424  {
1425  eventLogInternal.WriteEvent(instance, null, values);
1426  }
1427  }
1428 
1441  public static void WriteEvent(string source, EventInstance instance, byte[] data, params object[] values)
1442  {
1443  using (EventLogInternal eventLogInternal = new EventLogInternal("", ".", CheckAndNormalizeSourceName(source)))
1444  {
1445  eventLogInternal.WriteEvent(instance, data, values);
1446  }
1447  }
1448 
1449  private static string CheckAndNormalizeSourceName(string source)
1450  {
1451  if (source == null)
1452  {
1453  source = string.Empty;
1454  }
1455  if (source.Length + "SYSTEM\\CurrentControlSet\\Services\\EventLog".Length > 254)
1456  {
1457  throw new ArgumentException(SR.GetString("ParameterTooLong", "source", 254 - "SYSTEM\\CurrentControlSet\\Services\\EventLog".Length));
1458  }
1459  return source;
1460  }
1461  }
1462 }
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
void WriteEntry(string message)
Writes an information type entry, with the given message text, to the event log.
Definition: EventLog.cs:1232
override void Dispose(bool disposing)
Releases the unmanaged resources used by the T:System.Diagnostics.EventLog, and optionally releases t...
Definition: EventLog.cs:719
static void WriteEvent(string source, EventInstance instance, params object[] values)
Writes an event log entry with the given event data and message replacement strings,...
Definition: EventLog.cs:1421
PlatformID
Identifies the operating system, or platform, supported by an assembly.
Definition: PlatformID.cs:8
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
string MachineName
Gets or sets the name of the computer on which to read or write events.
Definition: EventLog.cs:115
Describes a set of security permissions applied to code. This class cannot be inherited.
static string LogNameFromSourceName(string source, string machineName)
Gets the name of the log to which the specified source is registered.
Definition: EventLog.cs:994
static bool SourceExists(string source)
Determines whether an event source is registered on the local computer.
Definition: EventLog.cs:957
EntryWrittenEventHandler EntryWritten
Occurs when an entry is written to an event log on the local computer.
Definition: EventLog.cs:249
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
static string Combine(string path1, string path2)
Combines two strings into a path.
Definition: Path.cs:1107
void Clear()
Removes all entries from the event log.
Definition: EventLog.cs:325
string Source
Gets or sets the name to register with the event log as an event source.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
EventLog(string logName, string machineName)
Initializes a new instance of the T:System.Diagnostics.EventLog class. Associates the instance with a...
Definition: EventLog.cs:292
void WriteEntry(string message, EventLogEntryType type, int eventID, short category, byte[] rawData)
Writes an entry with the given message text, application-defined event identifier,...
Definition: EventLog.cs:1372
Controls the ability to access registry variables. This class cannot be inherited.
string Source
Gets or sets the source name to register and use when writing to the event log.
Definition: EventLog.cs:226
void ReleaseMutex()
Releases the T:System.Threading.Mutex once.
Definition: Mutex.cs:377
The file is read-only.
Represents the configuration settings used to create an event log source on the local computer or a r...
EventLogEntryType
Specifies the event type of an event log entry.
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2255
Definition: __Canon.cs:3
EventLog(string logName)
Initializes a new instance of the T:System.Diagnostics.EventLog class. Associates the instance with a...
Definition: EventLog.cs:282
void Close()
Closes the event log and releases read and write handles.
Definition: EventLog.cs:332
static OperatingSystem OSVersion
Gets an T:System.OperatingSystem object that contains the current platform identifier and version num...
Definition: Environment.cs:477
void WriteEvent(EventInstance instance, byte[] data, params object[] values)
Writes an event log entry with the given event data, message replacement strings, and associated bina...
Definition: EventLog.cs:1405
A synchronization primitive that can also be used for interprocess synchronization.
Definition: Mutex.cs:17
static void WriteEvent(string source, EventInstance instance, byte[] data, params object[] values)
Writes an event log entry with the given event data, message replacement strings, and associated bina...
Definition: EventLog.cs:1441
string LogDisplayName
Gets the event log's friendly name.
Definition: EventLog.cs:72
static void WriteEntry(string source, string message, EventLogEntryType type, int eventID)
Writes an entry with the given message text and application-defined event identifier to the event log...
Definition: EventLog.cs:1301
Represents language-neutral information for an event log entry.
Definition: EventInstance.cs:6
Provides a way to synchronously or asynchronously execute a delegate.
string MachineName
Gets or sets the name of the computer on which to register the event source.
static void WriteEntry(string source, string message, EventLogEntryType type)
Writes an error, warning, information, success audit, or failure audit entry with the given message t...
Definition: EventLog.cs:1270
static void WriteEntry(string source, string message, EventLogEntryType type, int eventID, short category)
Writes an entry with the given message text, application-defined event identifier,...
Definition: EventLog.cs:1334
void EndInit()
Ends the initialization of an T:System.Diagnostics.EventLog used on a form or by another component....
Definition: EventLog.cs:729
static EventLog [] GetEventLogs(string machineName)
Searches for all event logs on the given computer and creates an array of T:System....
Definition: EventLog.cs:893
void WriteEntry(string message, EventLogEntryType type, int eventID, short category)
Writes an entry with the given message text, application-defined event identifier,...
Definition: EventLog.cs:1317
Version Version
Gets a T:System.Version object that identifies the operating system.
IPermission AddPermission(IPermission perm)
Adds a specified permission to the T:System.Security.PermissionSet.
NumberStyles
Determines the styles permitted in numeric string arguments that are passed to the Parse and TryParse...
Definition: NumberStyles.cs:10
ISynchronizeInvoke SynchronizingObject
Gets or sets the object used to marshal the event handler calls issued as a result of an T:System....
Definition: EventLog.cs:205
EventLogPermissionAccess
Defines access levels used by T:System.Diagnostics.EventLog permission classes.
PlatformID Platform
Gets a T:System.PlatformID enumeration value that identifies the operating system platform.
EventLog()
Initializes a new instance of the T:System.Diagnostics.EventLog class. Does not associate the instanc...
Definition: EventLog.cs:273
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
int Major
Gets the value of the major component of the version number for the current T:System....
Definition: Version.cs:103
Represents a collection that can contain many different types of permissions.
int MinimumRetentionDays
Gets the number of days to retain entries in the event log.
Definition: EventLog.cs:171
static bool Exists(string logName)
Determines whether the log exists on the local computer.
Definition: EventLog.cs:739
int Length
Gets or sets the length of the current T:System.Text.StringBuilder object.
static void DeleteEventSource(string source)
Removes the event source registration from the event log of the local computer.
Definition: EventLog.cs:635
void WriteEntry(string message, EventLogEntryType type)
Writes an error, warning, information, success audit, or failure audit entry with the given message t...
Definition: EventLog.cs:1256
Defines the underlying structure of all code access permissions.
static void PrepareConstrainedRegions()
Designates a body of code as a constrained execution region (CER).
Provides the base implementation for the T:System.ComponentModel.IComponent interface and enables obj...
Definition: Component.cs:9
static void CreateEventSource(EventSourceCreationData sourceData)
Establishes a valid event source for writing localized event messages, using the specified configurat...
Definition: EventLog.cs:371
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
bool EnableRaisingEvents
Gets or sets a value indicating whether the T:System.Diagnostics.EventLog receives E:System....
Definition: EventLog.cs:188
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
static GCHandle Alloc(object value)
Allocates a F:System.Runtime.InteropServices.GCHandleType.Normal handle for the specified object.
Definition: GCHandle.cs:98
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Definition: Marshal.cs:15
GCHandleType
Represents the types of handles the T:System.Runtime.InteropServices.GCHandle class can allocate.
Definition: GCHandleType.cs:7
string Log
Gets or sets the name of the log to read from or write to.
Definition: EventLog.cs:87
static string GetFullPath(string path)
Returns the absolute path for the specified path string.
Definition: Path.cs:446
Provides a way to access a managed object from unmanaged memory.
Definition: GCHandle.cs:10
IntPtr AddrOfPinnedObject()
Retrieves the address of an object in a F:System.Runtime.InteropServices.GCHandleType....
Definition: GCHandle.cs:138
long MaximumKilobytes
Gets or sets the maximum event log size in kilobytes.
Definition: EventLog.cs:143
Defines size and enumerators for a collection of T:System.Diagnostics.EventLogEntry instances.
virtual void CopyTo(Array array)
Copies the entire T:System.Collections.ArrayList to a compatible one-dimensional T:System....
Definition: ArrayList.cs:2516
static void Delete(string logName, string machineName)
Removes an event log from the specified computer.
Definition: EventLog.cs:552
string LogName
Gets or sets the name of the event log to which the source writes entries.
EventLog(string logName, string machineName, string source)
Initializes a new instance of the T:System.Diagnostics.EventLog class. Associates the instance with a...
Definition: EventLog.cs:303
static bool Exists(string logName, string machineName)
Determines whether the log exists on the specified computer.
Definition: EventLog.cs:750
virtual void Close()
Releases all resources held by the current T:System.Threading.WaitHandle.
Definition: WaitHandle.cs:714
static void WriteEntry(string source, string message)
Writes an information type entry with the given message text to the event log, using the specified re...
Definition: EventLog.cs:1243
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2381
static void RevertAssert()
Causes any previous M:System.Security.CodeAccessPermission.Assert for the current frame to be removed...
virtual object GetService(Type service)
Returns an object that represents a service provided by the T:System.ComponentModel....
Definition: Component.cs:131
Represents information about an operating system, such as the version and platform identifier....
static void CreateEventSource(string source, string logName)
Establishes the specified source name as a valid event source for writing entries to a log on the loc...
Definition: EventLog.cs:345
void BeginInit()
Begins the initialization of an T:System.Diagnostics.EventLog used on a form or used by another compo...
Definition: EventLog.cs:316
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
Provides interaction with Windows event logs.
Definition: EventLog.cs:20
void Free()
Releases a T:System.Runtime.InteropServices.GCHandle.
Definition: GCHandle.cs:119
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 ...
Definition: Array.cs:1275
static bool CheckMachineName(string value)
Checks the syntax of the machine name to confirm that it does not contain "\".
Definition: SyntaxCheck.cs:14
UnicodeCategory
Defines the Unicode category of a character.
int Capacity
Gets or sets the maximum number of characters that can be contained in the memory allocated by the cu...
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
DesignerSerializationVisibility
Specifies the visibility a property has to the design-time serializer.
static void DeleteEventSource(string source, string machineName)
Removes the application's event source registration from the specified computer.
Definition: EventLog.cs:646
Controls code access permissions for event logging.
EventLogEntryCollection Entries
Gets the contents of the event log.
Definition: EventLog.cs:60
OverflowAction
Specifies how to handle entries in an event log that has reached its maximum file size.
The exception that is thrown when a method call is invalid for the object's current state.
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
Definition: File.cs:14
Controls access to system and user environment variables. This class cannot be inherited.
static void CreateEventSource(string source, string logName, string machineName)
Establishes the specified source name as a valid event source for writing entries to a log on the spe...
Definition: EventLog.cs:360
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
static bool SourceExists(string source, string machineName)
Determines whether an event source is registered on a specified computer.
Definition: EventLog.cs:971
static void Delete(string path)
Deletes the specified file.
Definition: File.cs:324
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
SecurityPermissionFlag
Specifies access flags for the security permission object.
void WriteEntry(string message, EventLogEntryType type, int eventID)
Writes an entry with the given message text and application-defined event identifier to the event log...
Definition: EventLog.cs:1285
Specifies that this object supports a simple, transacted notification for batch initialization.
void RegisterDisplayName(string resourceFile, long resourceId)
Specifies the localized name of the event log, which is displayed in the server Event Viewer.
Definition: EventLog.cs:1036
static EventLog [] GetEventLogs()
Searches for all event logs on the local computer and creates an array of T:System....
Definition: EventLog.cs:883
The exception that is thrown when a security error is detected.
Provides a unified way of converting types of values to other types, as well as for accessing standar...
static void WriteEntry(string source, string message, EventLogEntryType type, int eventID, short category, byte[] rawData)
Writes an entry with the given message text, application-defined event identifier,...
Definition: EventLog.cs:1352
Performs operations on T:System.String instances that contain file or directory path information....
Definition: Path.cs:13
Provides methods to verify the machine name and path conform to a specific syntax....
Definition: SyntaxCheck.cs:8
void ModifyOverflowPolicy(OverflowAction action, int retentionDays)
Changes the configured behavior for writing new entries when the event log reaches its maximum file s...
Definition: EventLog.cs:1024
static void Delete(string logName)
Removes an event log from the local computer.
Definition: EventLog.cs:539
Provides a set of static methods and properties that provide support for compilers....
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Definition: ArrayList.cs:14
void WriteEvent(EventInstance instance, params object[] values)
Writes a localized entry to the event log.
Definition: EventLog.cs:1388
delegate void EntryWrittenEventHandler(object sender, EntryWrittenEventArgs e)
Represents the method that will handle the E:System.Diagnostics.EventLog.EntryWritten event of an T:S...