-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathEventLog.xml
5215 lines (4336 loc) · 375 KB
/
EventLog.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<Type Name="EventLog" FullName="System.Diagnostics.EventLog">
<TypeSignature Language="C#" Value="public class EventLog : System.ComponentModel.Component, System.ComponentModel.ISupportInitialize" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit EventLog extends System.ComponentModel.Component implements class System.ComponentModel.ISupportInitialize" />
<TypeSignature Language="DocId" Value="T:System.Diagnostics.EventLog" />
<TypeSignature Language="VB.NET" Value="Public Class EventLog
Inherits Component
Implements ISupportInitialize" />
<TypeSignature Language="F#" Value="type EventLog = class
 inherit Component
 interface ISupportInitialize" />
<TypeSignature Language="C++ CLI" Value="public ref class EventLog : System::ComponentModel::Component, System::ComponentModel::ISupportInitialize" />
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.EventLog</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<TypeForwardingChain>
<TypeForwarding From="System.Diagnostics.EventLog" FromVersion="9.0.0.0" To="System" ToVersion="4.0.0.0" FrameworkAlternate="netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
</TypeForwardingChain>
<Base>
<BaseTypeName>System.ComponentModel.Component</BaseTypeName>
</Base>
<Interfaces>
<Interface>
<InterfaceName>System.ComponentModel.ISupportInitialize</InterfaceName>
</Interface>
</Interfaces>
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.ComponentModel.DefaultEvent("EntryWritten")]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.DefaultEvent("EntryWritten")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-1.1">
<AttributeName Language="C#">[System.ComponentModel.Designer("Microsoft.VisualStudio.Install.EventLogInstallableComponentDesigner, Microsoft.VisualStudio, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.Designer("Microsoft.VisualStudio.Install.EventLogInstallableComponentDesigner, Microsoft.VisualStudio, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-1.1">
<AttributeName Language="C#">[System.ComponentModel.InstallerType("System.Diagnostics.EventLogInstaller, System.Configuration.Install, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.InstallerType("System.Diagnostics.EventLogInstaller, System.Configuration.Install, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5">
<AttributeName Language="C#">[System.ComponentModel.InstallerType("System.Diagnostics.EventLogInstaller, System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.InstallerType("System.Diagnostics.EventLogInstaller, System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1">
<AttributeName Language="C#">[System.Diagnostics.MonitoringDescription("EventLogDesc")]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.MonitoringDescription("EventLogDesc")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1">
<AttributeName Language="C#">[System.ComponentModel.InstallerType("System.Diagnostics.EventLogInstaller, System.Configuration.Install, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.InstallerType("System.Diagnostics.EventLogInstaller, System.Configuration.Install, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Provides interaction with Windows event logs.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
<xref:System.Diagnostics.EventLog> lets you access or customize Windows event logs, which record information about important software or hardware events. Using <xref:System.Diagnostics.EventLog>, you can read from existing logs, write entries to logs, create or delete event sources, delete logs, and respond to log entries. You can also create new logs when creating an event source.
> [!IMPORTANT]
> This type implements the <xref:System.IDisposable> interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its <xref:System.IDisposable.Dispose%2A> method in a `try`/`catch` block. To dispose of it indirectly, use a language construct such as `using` (in C#) or `Using` (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the <xref:System.IDisposable> interface topic.
In addition to providing access to individual event logs and their entries, the <xref:System.Diagnostics.EventLog> class lets you access the collection of all event logs. You can use the `static` members of <xref:System.Diagnostics.EventLog> to delete logs, get log lists, create or delete a source, or determine if a computer already contains a particular source.
There are three default event logs: Application, System, and Security. A Security log is read-only. Other applications and services you install, such as Active Directory, might have additional event logs.
There are security considerations when using the <xref:System.Diagnostics.EventLog> class. <xref:System.Diagnostics.EventLog> requires <xref:System.Diagnostics.EventLogPermission> permissions for specific actions in the .NET Framework 2.0 and later versions, or full trust in the .NET Framework 1.0 and 1.1. We recommend that <xref:System.Diagnostics.EventLogPermission> not be granted to partially trusted code. You should never pass any event log object, including <xref:System.Diagnostics.EventLogEntryCollection> and <xref:System.Diagnostics.EventLogEntry> objects, to less trusted code. For example, creating an <xref:System.Diagnostics.EventLog> object, writing an entry, and then passing the <xref:System.Diagnostics.EventLog> object to partially trusted code can create a security issue, because the ability to read and write to the event log allows code to perform actions such as issuing event log messages in the name of another application.
Starting with Windows Vista, User Account Control (UAC) determines the credentials of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. To run the code that accesses the Security log, you must first elevate your credentials from standard user to administrator. You can do this when you start an application by opening the shortcut menu for the application (if you're using a mouse, right-click the application icon) and indicating that you want to run as an administrator.
You can use <xref:System.Diagnostics.EventLog> to create custom event logs that you can view through the server's Event Viewer. Use the <xref:System.Diagnostics.EventLog.RegisterDisplayName%2A> method to display a localized name for your event log in the Event Viewer. Use the <xref:System.Diagnostics.EventLog.ModifyOverflowPolicy%2A> method to configure the behavior of your event log when it reaches its maximum log size.
To read from an event log, specify the log name (<xref:System.Diagnostics.EventLog.Log%2A> property) and server computer name (<xref:System.Diagnostics.EventLog.MachineName%2A> property for the event log. If you don't specify the server computer name, the local computer, ".", is assumed. It's not necessary to specify the event source (<xref:System.Diagnostics.EventLog.Source%2A> property), because a source is required only for writing to logs. The <xref:System.Diagnostics.EventLog.Entries%2A> property is automatically populated with the event log's list of entries.
To write to an event log, specify or create an event source (<xref:System.Diagnostics.EventLog.Source%2A> property). You must have administrative credentials on the computer to create a new event source. The event source registers your application with the event log as a valid source of entries. You can use the event source to write to only one log at a time. The <xref:System.Diagnostics.EventLog.Source%2A> property can be any random string, but the name must be distinct from other sources on the computer. The event source is typically the name of the application or another identifying string. Trying to create a duplicate <xref:System.Diagnostics.EventLog.Source%2A> value throws an exception. However, a single event log can be associated with multiple sources.
If the event source for the event log associated with the <xref:System.Diagnostics.EventLog> instance doesn't exist, a new event source is created. To create an event source in Windows Vista and later or Windows Server 2003, you must have administrative credentials.
This requirement is because all event logs, including Security logs, must be searched to determine whether the event source is unique. Starting with Windows Vista, users do not have permission to access the Security log; therefore, a <xref:System.Security.SecurityException> is thrown.
> [!IMPORTANT]
> Creating or deleting an event source requires synchronization of the underlying code by using a named mutex. If a highly privileged application locks the named mutex, trying to create or delete an event source causes the application to stop responding until the lock is released. To help prevent this problem, never grant <xref:System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode> permission to untrusted code. In addition, <xref:System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode> permission potentially allows other permissions to be bypassed and should only be granted to highly trusted code.
Applications and services should write to the Application log or to a custom log. Device drivers should write to the System log. If you do not explicitly set the <xref:System.Diagnostics.EventLog.Log%2A> property, the event log defaults to the Application log.
> [!NOTE]
> There is nothing to protect an application from writing as any registered source. If an application is granted <xref:System.Diagnostics.EventLogPermissionAccess.Write> permission, it can write events for any valid source registered on the computer.
Use the <xref:System.Diagnostics.EventLog.WriteEvent%2A> and <xref:System.Diagnostics.EventLog.WriteEntry%2A> methods to write events to an event log. You must specify an event source to write events; you must create and configure the event source before writing the first entry with the source.
Create the new event source during the installation of your application. This allows time for the operating system to refresh its list of registered event sources and their configuration. If the operating system hasn't refreshed its list of event sources, and you try to write an event with the new source, the write operation will fail. You can configure a new source by using an <xref:System.Diagnostics.EventLogInstaller> object or the <xref:System.Diagnostics.EventLog.CreateEventSource%2A> method. You must have administrative credentials on the computer to create a new event source.
Each source can write to only one event log at a time; however, your application can use multiple sources to write to multiple event logs. For example, your application might require multiple sources configured for different event logs or different resource files. To change the configuration details of an existing source, you must delete the source and then create it with the new configuration. If other applications or components use the existing source, create a new source with the updated configuration instead of deleting the existing source.
You can register the event source with localized resources for your event category and message strings. Your application can write event log entries by using resource identifiers instead of specifying the actual string values. Refer to the <xref:System.Diagnostics.EventLogInstaller> and <xref:System.Diagnostics.EventSourceCreationData> classes for more information about configuring your source with resource files.
If your application writes string values directly to the event log, you do not have to set the resource file properties for the source. The source must be configured either for writing localized entries or for writing direct strings. If your application writes entries using both resource identifiers and string values, you must register two separate sources. For example, configure one source with resource files, and then use that source in the <xref:System.Diagnostics.EventLog.WriteEvent%2A> method to write entries using resource identifiers to the event log. Then create a different source without resource files, and use that source in the <xref:System.Diagnostics.EventLog.WriteEntry%2A> method to write strings directly to the event log using that source.
When writing events, you must at least specify either a message string or the resource identifier for a message string. Other event properties are optional. Examples of optional event settings include the following:
- You can set the <xref:System.Diagnostics.EventLogEntryType> to specify the icon that the Event Viewer displays for the entry.
- You can specify a category identifier for the event, if your application uses categories for filtering the events.
- You can attach binary data to your event entry if you want to associate additional information with a given event.
> [!IMPORTANT]
> Event logging consumes disk space, processor time, and other system resources. It is important to log only essential information. We recommend that you place event log calls in an error path, rather than in the main code path, so they don't adversely affect performance.
For a list of initial property values for an instance of <xref:System.Diagnostics.EventLog>, see the <xref:System.Diagnostics.EventLog.%23ctor%2A> constructor.
## Examples
The following example creates the event source `MySource` if it doesn't already exist, and writes an entry to the event log `MyNewLog`.
> [!NOTE]
> Starting with Windows Vista, you must run this application as an administrator.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic EventLog.CreateEventSource Example/CPP/source.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/EventLog/Overview/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic EventLog.CreateEventSource Example/VB/source.vb" id="Snippet1":::
]]></format>
</remarks>
<altmember cref="T:System.Diagnostics.EventLogInstaller" />
<altmember cref="T:System.Diagnostics.EventLogEntry" />
<altmember cref="T:System.Diagnostics.EntryWrittenEventArgs" />
<altmember cref="T:System.ServiceProcess.ServiceBase" />
</Docs>
<Members>
<MemberGroup MemberName=".ctor">
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Diagnostics.EventLog" /> class.</summary>
</Docs>
</MemberGroup>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public EventLog ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.EventLog.#ctor" />
<MemberSignature Language="VB.NET" Value="Public Sub New ()" />
<MemberSignature Language="C++ CLI" Value="public:
 EventLog();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.EventLog</AssemblyName>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<Parameters />
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Diagnostics.EventLog" /> class. Does not associate the instance with any log.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Before calling <xref:System.Diagnostics.EventLog.WriteEntry%2A>, specify the <xref:System.Diagnostics.EventLog.Source%2A> property of the <xref:System.Diagnostics.EventLog> instance. If you are only reading <xref:System.Diagnostics.EventLog.Entries%2A> from the log, you can alternatively specify only the <xref:System.Diagnostics.EventLog.Log%2A> and <xref:System.Diagnostics.EventLog.MachineName%2A> properties.
> [!NOTE]
> If you do not specify a <xref:System.Diagnostics.EventLog.MachineName%2A>, the local computer (".") is assumed.
The following table shows initial property values for an instance of <xref:System.Diagnostics.EventLog>.
|Property|Initial Value|
|--------------|-------------------|
|<xref:System.Diagnostics.EventLog.Source%2A>|An empty string ("").|
|<xref:System.Diagnostics.EventLog.Log%2A>|An empty string ("").|
|<xref:System.Diagnostics.EventLog.MachineName%2A>|The local computer (".").|
## Examples
The following example creates the source `MySource` if it does not already exist, and writes an entry to the event log `MyNewLog`.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic EventLog.CreateEventSource Example/CPP/source.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/EventLog/Overview/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic EventLog.CreateEventSource Example/VB/source.vb" id="Snippet1":::
]]></format>
</remarks>
<altmember cref="P:System.Diagnostics.EventLog.Source" />
<altmember cref="P:System.Diagnostics.EventLog.Log" />
<altmember cref="P:System.Diagnostics.EventLog.MachineName" />
<altmember cref="P:System.Diagnostics.EventLog.Entries" />
<altmember cref="Overload:System.Diagnostics.EventLog.WriteEntry" />
<altmember cref="Overload:System.Diagnostics.EventLog.WriteEvent" />
<altmember cref="T:System.Diagnostics.EventLogEntry" />
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public EventLog (string logName);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string logName) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.EventLog.#ctor(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (logName As String)" />
<MemberSignature Language="F#" Value="new System.Diagnostics.EventLog : string -> System.Diagnostics.EventLog" Usage="new System.Diagnostics.EventLog logName" />
<MemberSignature Language="C++ CLI" Value="public:
 EventLog(System::String ^ logName);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.EventLog</AssemblyName>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<Parameters>
<Parameter Name="logName" Type="System.String" />
</Parameters>
<Docs>
<param name="logName">The name of the log on the local computer.</param>
<summary>Initializes a new instance of the <see cref="T:System.Diagnostics.EventLog" /> class. Associates the instance with a log on the local computer.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This overload sets the <xref:System.Diagnostics.EventLog.Log%2A> property to the `logName` parameter. Before calling <xref:System.Diagnostics.EventLog.WriteEntry%2A>, specify the <xref:System.Diagnostics.EventLog.Source%2A> property of the <xref:System.Diagnostics.EventLog> instance. If you are only reading <xref:System.Diagnostics.EventLog.Entries%2A> from the log, you can alternatively specify only the <xref:System.Diagnostics.EventLog.Log%2A> and <xref:System.Diagnostics.EventLog.MachineName%2A> properties.
> [!NOTE]
> If you do not specify a <xref:System.Diagnostics.EventLog.MachineName%2A>, the local computer (".") is assumed. This overload of the constructor specifies the <xref:System.Diagnostics.EventLog.Log%2A> property, but you can change this before reading the <xref:System.Diagnostics.EventLog.Entries%2A> property.
If the source you specify in the <xref:System.Diagnostics.EventLog.Source%2A> property is unique from other sources on the computer, a subsequent call to <xref:System.Diagnostics.EventLog.WriteEntry%2A> creates a log with the specified name, if it does not already exist.
The following table shows initial property values for an instance of <xref:System.Diagnostics.EventLog>.
|Property|Initial Value|
|--------------|-------------------|
|<xref:System.Diagnostics.EventLog.Source%2A>|An empty string ("").|
|<xref:System.Diagnostics.EventLog.Log%2A>|The `logName` parameter.|
|<xref:System.Diagnostics.EventLog.MachineName%2A>|The local computer (".").|
## Examples
The following example reads entries in the event log, "myNewLog", on the local computer.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic EventLog.EventLog1 Example/CPP/source.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/EventLog/.ctor/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic EventLog.EventLog1 Example/VB/source.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">The log name is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">The log name is invalid.</exception>
<altmember cref="P:System.Diagnostics.EventLog.Source" />
<altmember cref="P:System.Diagnostics.EventLog.Log" />
<altmember cref="P:System.Diagnostics.EventLog.MachineName" />
<altmember cref="P:System.Diagnostics.EventLog.Entries" />
<altmember cref="Overload:System.Diagnostics.EventLog.WriteEntry" />
<altmember cref="Overload:System.Diagnostics.EventLog.WriteEvent" />
<altmember cref="T:System.Diagnostics.EventLogEntry" />
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public EventLog (string logName, string machineName);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string logName, string machineName) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.EventLog.#ctor(System.String,System.String)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (logName As String, machineName As String)" />
<MemberSignature Language="F#" Value="new System.Diagnostics.EventLog : string * string -> System.Diagnostics.EventLog" Usage="new System.Diagnostics.EventLog (logName, machineName)" />
<MemberSignature Language="C++ CLI" Value="public:
 EventLog(System::String ^ logName, System::String ^ machineName);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.EventLog</AssemblyName>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<Parameters>
<Parameter Name="logName" Type="System.String" />
<Parameter Name="machineName" Type="System.String" />
</Parameters>
<Docs>
<param name="logName">The name of the log on the specified computer.</param>
<param name="machineName">The computer on which the log exists.</param>
<summary>Initializes a new instance of the <see cref="T:System.Diagnostics.EventLog" /> class. Associates the instance with a log on the specified computer.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This overload sets the <xref:System.Diagnostics.EventLog.Log%2A> property to the `logName` parameter and the <xref:System.Diagnostics.EventLog.MachineName%2A> property to the `machineName` parameter. Before calling <xref:System.Diagnostics.EventLog.WriteEntry%2A>, specify the <xref:System.Diagnostics.EventLog.Source%2A> property of the <xref:System.Diagnostics.EventLog>. If you are only reading <xref:System.Diagnostics.EventLog.Entries%2A> from the log, you can alternatively specify only the <xref:System.Diagnostics.EventLog.Log%2A> and <xref:System.Diagnostics.EventLog.MachineName%2A> properties.
> [!NOTE]
> This overload of the constructor specifies the <xref:System.Diagnostics.EventLog.Log%2A> and <xref:System.Diagnostics.EventLog.MachineName%2A> properties, but you can change either before reading the <xref:System.Diagnostics.EventLog.Entries%2A> property.
The following table shows initial property values for an instance of <xref:System.Diagnostics.EventLog>.
|Property|Initial Value|
|--------------|-------------------|
|<xref:System.Diagnostics.EventLog.Source%2A>|An empty string ("").|
|<xref:System.Diagnostics.EventLog.Log%2A>|The `logName` parameter.|
|<xref:System.Diagnostics.EventLog.MachineName%2A>|The `machineName` parameter.|
## Examples
The following example reads entries in the event log, "myNewLog", on the computer "myServer".
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic EventLog.EventLog2 Example/CPP/source.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/EventLog/.ctor/source1.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic EventLog.EventLog2 Example/VB/source.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">The log name is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">The log name is invalid.
-or-
The computer name is invalid.</exception>
<altmember cref="P:System.Diagnostics.EventLog.Source" />
<altmember cref="P:System.Diagnostics.EventLog.Log" />
<altmember cref="P:System.Diagnostics.EventLog.MachineName" />
<altmember cref="P:System.Diagnostics.EventLog.Entries" />
<altmember cref="Overload:System.Diagnostics.EventLog.WriteEntry" />
<altmember cref="Overload:System.Diagnostics.EventLog.WriteEvent" />
<altmember cref="T:System.Diagnostics.EventLogEntry" />
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public EventLog (string logName, string machineName, string source);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string logName, string machineName, string source) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.EventLog.#ctor(System.String,System.String,System.String)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (logName As String, machineName As String, source As String)" />
<MemberSignature Language="F#" Value="new System.Diagnostics.EventLog : string * string * string -> System.Diagnostics.EventLog" Usage="new System.Diagnostics.EventLog (logName, machineName, source)" />
<MemberSignature Language="C++ CLI" Value="public:
 EventLog(System::String ^ logName, System::String ^ machineName, System::String ^ source);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.EventLog</AssemblyName>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters>
<Parameter Name="logName" Type="System.String" />
<Parameter Name="machineName" Type="System.String" />
<Parameter Name="source" Type="System.String" />
</Parameters>
<Docs>
<param name="logName">The name of the log on the specified computer.</param>
<param name="machineName">The computer on which the log exists.</param>
<param name="source">The source of event log entries.</param>
<summary>Initializes a new instance of the <see cref="T:System.Diagnostics.EventLog" /> class. Associates the instance with a log on the specified computer and creates or assigns the specified source to the <see cref="T:System.Diagnostics.EventLog" />.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This constructor sets the <xref:System.Diagnostics.EventLog.Log%2A> property to the `logName` parameter, the <xref:System.Diagnostics.EventLog.MachineName%2A> property to the `machineName` parameter, and the <xref:System.Diagnostics.EventLog.Source%2A> property to the `source` parameter. The <xref:System.Diagnostics.EventLog.Source%2A> property is required when writing to an event log. However, if you are only reading from an event log, only the <xref:System.Diagnostics.EventLog.Log%2A> and <xref:System.Diagnostics.EventLog.MachineName%2A> properties are required (as long as the event log on the server has a source already associated with it). If you are only reading from the event log, another overload of the constructor might suffice.
The following table shows initial property values for an instance of <xref:System.Diagnostics.EventLog>.
|Property|Initial Value|
|--------------|-------------------|
|<xref:System.Diagnostics.EventLog.Source%2A>|The `source` parameter.|
|<xref:System.Diagnostics.EventLog.Log%2A>|The `logName` parameter.|
|<xref:System.Diagnostics.EventLog.MachineName%2A>|The `machineName` parameter.|
## Examples
The following example writes an entry to an event log, "MyNewLog", on the local computer, using the source "MySource".
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic EventLog.EventLog3 Example/CPP/source.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/EventLog/.ctor/source2.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic EventLog.EventLog3 Example/VB/source.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">The log name is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">The log name is invalid.
-or-
The computer name is invalid.</exception>
<altmember cref="P:System.Diagnostics.EventLog.Source" />
<altmember cref="P:System.Diagnostics.EventLog.Log" />
<altmember cref="P:System.Diagnostics.EventLog.MachineName" />
<altmember cref="P:System.Diagnostics.EventLog.Entries" />
<altmember cref="Overload:System.Diagnostics.EventLog.WriteEntry" />
<altmember cref="Overload:System.Diagnostics.EventLog.WriteEvent" />
<altmember cref="T:System.Diagnostics.EventLogEntry" />
</Docs>
</Member>
<Member MemberName="BeginInit">
<MemberSignature Language="C#" Value="public void BeginInit ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance void BeginInit() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.EventLog.BeginInit" />
<MemberSignature Language="VB.NET" Value="Public Sub BeginInit ()" />
<MemberSignature Language="F#" Value="abstract member BeginInit : unit -> unit
override this.BeginInit : unit -> unit" Usage="eventLog.BeginInit " />
<MemberSignature Language="C++ CLI" Value="public:
 virtual void BeginInit();" />
<MemberType>Method</MemberType>
<Implements>
<InterfaceMember>M:System.ComponentModel.ISupportInitialize.BeginInit</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.EventLog</AssemblyName>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Begins the initialization of an <see cref="T:System.Diagnostics.EventLog" /> used on a form or used by another component. The initialization occurs at runtime.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The Visual Studio 2005 design environment uses this method to start the initialization of a component used on a form or by another component. The <xref:System.Diagnostics.EventLog.EndInit%2A> method ends the initialization. Using the <xref:System.Diagnostics.EventLog.BeginInit%2A> and <xref:System.Diagnostics.EventLog.EndInit%2A> methods prevent the control from being used before it is fully initialized.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">
<see cref="T:System.Diagnostics.EventLog" /> is already initialized.</exception>
<altmember cref="M:System.Diagnostics.EventLog.EndInit" />
</Docs>
</Member>
<Member MemberName="Clear">
<MemberSignature Language="C#" Value="public void Clear ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void Clear() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.EventLog.Clear" />
<MemberSignature Language="VB.NET" Value="Public Sub Clear ()" />
<MemberSignature Language="F#" Value="member this.Clear : unit -> unit" Usage="eventLog.Clear " />
<MemberSignature Language="C++ CLI" Value="public:
 void Clear();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.EventLog</AssemblyName>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Removes all entries from the event log.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Event logs are set with a maximum size that determines how many entries they can contain. When an event log is full, it stops recording new event information or begins to overwrite earlier entries. If event recording stops, you can use this method to clear the log of existing entries and allow it to start recording events again. You must have administrator permissions to the computer on which the log resides to clear event log entries.
<xref:System.Diagnostics.EventLog.Clear%2A> closes the event log, releases the event handles, retrieves new read and write handles, and reopens the event log. Events received after the call to the method are not cleared along with the existing events.
## Examples
The following example clears an event log.
> [!CAUTION]
> Because Application, System, Security, and other non-custom logs can contain crucial information; be sure to specify a custom log before executing this example code. This example deletes the custom log `myNewLog`.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic EventLog.Clear Example/CPP/source.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/EventLog/Clear/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic EventLog.Clear Example/VB/source.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ComponentModel.Win32Exception">The event log was not cleared successfully.
-or-
The log cannot be opened. A Windows error code is not available.</exception>
<exception cref="T:System.ArgumentException">A value is not specified for the <see cref="P:System.Diagnostics.EventLog.Log" /> property. Make sure the log name is not an empty string.</exception>
<exception cref="T:System.InvalidOperationException">The log does not exist.</exception>
<altmember cref="M:System.Diagnostics.EventLog.Close" />
<altmember cref="M:System.Diagnostics.EventLog.Delete(System.String)" />
</Docs>
</Member>
<Member MemberName="Close">
<MemberSignature Language="C#" Value="public void Close ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void Close() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.EventLog.Close" />
<MemberSignature Language="VB.NET" Value="Public Sub Close ()" />
<MemberSignature Language="F#" Value="member this.Close : unit -> unit" Usage="eventLog.Close " />
<MemberSignature Language="C++ CLI" Value="public:
 void Close();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.EventLog</AssemblyName>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Closes the event log and releases read and write handles.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Diagnostics.EventLog.Close%2A> method is called by the protected <xref:System.ComponentModel.Component.Dispose%2A> method. You do not need to invoke <xref:System.Diagnostics.EventLog.Close%2A> before calling <xref:System.ComponentModel.Component.Dispose%2A>.
]]></format>
</remarks>
<exception cref="T:System.ComponentModel.Win32Exception">The event log's read handle or write handle was not released successfully.</exception>
<altmember cref="M:System.Diagnostics.EventLog.Delete(System.String)" />
<altmember cref="M:System.Diagnostics.EventLog.Clear" />
</Docs>
</Member>
<MemberGroup MemberName="CreateEventSource">
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Establishes an application as able to write event information to a particular log on the system.</summary>
</Docs>
</MemberGroup>
<Member MemberName="CreateEventSource">
<MemberSignature Language="C#" Value="public static void CreateEventSource (System.Diagnostics.EventSourceCreationData sourceData);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void CreateEventSource(class System.Diagnostics.EventSourceCreationData sourceData) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.EventLog.CreateEventSource(System.Diagnostics.EventSourceCreationData)" />
<MemberSignature Language="VB.NET" Value="Public Shared Sub CreateEventSource (sourceData As EventSourceCreationData)" />
<MemberSignature Language="F#" Value="static member CreateEventSource : System.Diagnostics.EventSourceCreationData -> unit" Usage="System.Diagnostics.EventLog.CreateEventSource sourceData" />
<MemberSignature Language="C++ CLI" Value="public:
 static void CreateEventSource(System::Diagnostics::EventSourceCreationData ^ sourceData);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.EventLog</AssemblyName>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="sourceData" Type="System.Diagnostics.EventSourceCreationData" Index="0" FrameworkAlternate="net-6.0;net-7.0;net-8.0;net-9.0;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;windowsdesktop-3.0;windowsdesktop-3.1;windowsdesktop-5.0;windowsdesktop-6.0;windowsdesktop-7.0;windowsdesktop-8.0;windowsdesktop-9.0" />
</Parameters>
<Docs>
<param name="sourceData">The configuration properties for the event source and its target event log.</param>
<summary>Establishes a valid event source for writing localized event messages, using the specified configuration properties for the event source and the corresponding event log.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Use this overload to configure a new source for writing entries to an event log on the local computer or a remote computer. It is not necessary to use this method to read from an event log.
The <xref:System.Diagnostics.EventLog.CreateEventSource%2A> method uses the input `sourceData` <xref:System.Diagnostics.EventSourceCreationData.Source%2A>, <xref:System.Diagnostics.EventSourceCreationData.LogName%2A> and <xref:System.Diagnostics.EventSourceCreationData.MachineName%2A> properties to create registry values on the target computer for the new source and its associated event log. A new source name cannot match an existing source name or an existing event log name on the target computer. If the <xref:System.Diagnostics.EventSourceCreationData.LogName%2A> property is not set, the source is registered for the Application event log. If the <xref:System.Diagnostics.EventSourceCreationData.MachineName%2A> is not set, the source is registered on the local computer.
> [!NOTE]
> To create an event source in Windows Vista and later or Windows Server 2003, you must have administrative privileges.
>
> The reason for this requirement is that all event logs, including security, must be searched to determine whether the event source is unique. Starting with Windows Vista, users do not have permission to access the security log; therefore, a <xref:System.Security.SecurityException> is thrown.
>
> Starting with Windows Vista, User Account Control (UAC) determines the privileges of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. To execute the code that accesses the security log, you must first elevate your privileges from standard user to administrator. You can do this when you start an application by right-clicking the application icon and indicating that you want to run as an administrator.
Use <xref:System.Diagnostics.EventLog.WriteEvent%2A> and <xref:System.Diagnostics.EventLog.WriteEntry%2A> to write events to an event log. You must specify an event source to write events; you must create and configure the event source before writing the first entry with the source.
Create the new event source during the installation of your application. This allows time for the operating system to refresh its list of registered event sources and their configuration. If the operating system has not refreshed its list of event sources, and you attempt to write an event with the new source, the write operation will fail. You can configure a new source using an <xref:System.Diagnostics.EventLogInstaller>, or using the <xref:System.Diagnostics.EventLog.CreateEventSource%2A> method. You must have administrative rights on the computer to create a new event source.
You can create an event source for an existing event log or a new event log. When you create a new source for a new event log, the system registers the source for that log, but the log is not created until the first entry is written to it.
The operating system stores event logs as files. When you use <xref:System.Diagnostics.EventLogInstaller> or <xref:System.Diagnostics.EventLog.CreateEventSource%2A> to create a new event log, the associated file is stored in the %SystemRoot%\System32\Config directory on the specified computer. The file name is set by appending the first 8 characters of the <xref:System.Diagnostics.EventLog.Log%2A> property with the ".evt" file name extension.
Each source can only write to only one event log at a time; however, your application can use multiple sources to write to multiple event logs. For example, your application might require multiple sources configured for different event logs or different resource files.
You can register the event source with localized resource file(s) for your event category and message strings. Your application can write event log entries using resource identifiers, rather than specifying the actual string. The Event Viewer uses the resource identifier to find and display the corresponding string from the localized resource file based on current language settings. You can register a separate file for event categories, messages and parameter insertion strings, or you can register the same resource file for all three types of strings. Use the <xref:System.Diagnostics.EventSourceCreationData.CategoryCount%2A>, <xref:System.Diagnostics.EventSourceCreationData.CategoryResourceFile%2A>, <xref:System.Diagnostics.EventSourceCreationData.MessageResourceFile%2A>, and <xref:System.Diagnostics.EventSourceCreationData.ParameterResourceFile%2A> properties to configure the source to write localized entries to the event log. If your application writes strings values directly to the event log, you do not need to set these properties.
The source must be configured either for writing localized entries or for writing direct strings. If your application writes entries using both resource identifiers and string values, you must register two separate sources. For example, configure one source with resource files, and then use that source in the <xref:System.Diagnostics.EventLog.WriteEvent%2A> method to write entries using resource identifiers to the event log. Then create a different source without resource files, and use that source in the <xref:System.Diagnostics.EventLog.WriteEntry%2A> method to write strings directly to the event log using that source.
To change the configuration details of an existing source, you must delete the source and then create it with the new configuration. If other applications or components use the existing source, create a new source with the updated configuration rather than deleting the existing source.
> [!NOTE]
> If a source is configured for an event log, and you reconfigure it for another event log, you must restart the computer for the changes to take effect.
## Examples
The following example determines whether the event source named `SampleApplicationSource` is registered on the local computer. If the event source does not exist, the example sets the message resource file for the source and creates the new event source. Finally, the example sets the localized display name for the event log, using the resource identifier value in `DisplayNameMsgId` and the resource file path in `messageFile`.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/eventlog_WriteEvent/CPP/source.cpp" id="Snippet6":::
:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/EventInstance/Overview/source.cs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/eventlog_WriteEvent/VB/source.vb" id="Snippet6":::
The example uses the following message text file, built into the resource library EventLogMsgs.dll. A message text file is the source from which the message resource file is created. The message text file defines the resource identifiers and text for the category, event message, and parameter insertion strings. Specifically, resource identifier 5001 is defined for the localized name of the event log.
```
; // EventLogMsgs.mc
; // ********************************************************
; // Use the following commands to build this file:
; // mc -s EventLogMsgs.mc
; // rc EventLogMsgs.rc
; // link /DLL /SUBSYSTEM:WINDOWS /NOENTRY /MACHINE:x86 EventLogMsgs.Res
; // ********************************************************
; // - Event categories -
; // Categories must be numbered consecutively starting at 1.
; // ********************************************************
MessageId=0x1
Severity=Success
SymbolicName=INSTALL_CATEGORY
Language=English
Installation
.
MessageId=0x2
Severity=Success
SymbolicName=QUERY_CATEGORY
Language=English
Database Query
.
MessageId=0x3
Severity=Success
SymbolicName=REFRESH_CATEGORY
Language=English
Data Refresh
.
; // - Event messages -
; // *********************************
MessageId = 1000
Severity = Success
Facility = Application
SymbolicName = AUDIT_SUCCESS_MESSAGE_ID_1000
Language=English
My application message text, in English, for message id 1000, called from %1.
.
MessageId = 1001
Severity = Warning
Facility = Application
SymbolicName = AUDIT_FAILED_MESSAGE_ID_1001
Language=English
My application message text, in English, for message id 1001, called from %1.
.
MessageId = 1002
Severity = Success
Facility = Application
SymbolicName = GENERIC_INFO_MESSAGE_ID_1002
Language=English
My generic information message in English, for message id 1002.
.
MessageId = 1003
Severity = Warning
Facility = Application
SymbolicName = GENERIC_WARNING_MESSAGE_ID_1003
Language=English
My generic warning message in English, for message id 1003, called from %1.
.
MessageId = 1004
Severity = Success
Facility = Application
SymbolicName = UPDATE_CYCLE_COMPLETE_MESSAGE_ID_1004
Language=English
The update cycle is complete for %%5002.
.
MessageId = 1005
Severity = Warning
Facility = Application
SymbolicName = SERVER_CONNECTION_DOWN_MESSAGE_ID_1005
Language=English
The refresh operation did not complete because the connection to server %1 could not be established.
.
; // - Event log display name -
; // ********************************************************
MessageId = 5001
Severity = Success
Facility = Application
SymbolicName = EVENT_LOG_DISPLAY_NAME_MSGID
Language=English
Sample Event Log
.
; // - Event message parameters -
; // Language independent insertion strings
; // ********************************************************
MessageId = 5002
Severity = Success
Facility = Application
SymbolicName = EVENT_LOG_SERVICE_NAME_MSGID
Language=English
SVC_UPDATE.EXE
.
```
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">The computer name specified in <paramref name="sourceData" /> is not valid.
-or-
The source name specified in <paramref name="sourceData" /> is <see langword="null" />.
-or-
The log name specified in <paramref name="sourceData" /> is not valid. Event log names must consist of printable characters and cannot include the characters '*', '?', or '\\'.
-or-
The log name specified in <paramref name="sourceData" /> is not valid for user log creation. The Event log names AppEvent, SysEvent, and SecEvent are reserved for system use.
-or-
The log name matches an existing event source name.
-or-
The source name specified in <paramref name="sourceData" /> results in a registry key path longer than 254 characters.
-or-
The first 8 characters of the log name specified in <paramref name="sourceData" /> are not unique.
-or-
The source name specified in <paramref name="sourceData" /> is already registered.
-or-
The source name specified in <paramref name="sourceData" /> matches an existing event log name.</exception>
<exception cref="T:System.InvalidOperationException">The registry key for the event log could not be opened.</exception>
<exception cref="T:System.ArgumentNullException">
<paramref name="sourceData" /> is <see langword="null" />.</exception>
<altmember cref="T:System.Diagnostics.EventSourceCreationData" />
<altmember cref="M:System.Diagnostics.EventLog.SourceExists(System.String)" />
<altmember cref="M:System.Diagnostics.EventLog.DeleteEventSource(System.String)" />
<altmember cref="P:System.Diagnostics.EventLog.Source" />
<altmember cref="T:System.Diagnostics.EventLogInstaller" />
</Docs>
</Member>
<Member MemberName="CreateEventSource">
<MemberSignature Language="C#" Value="public static void CreateEventSource (string source, string logName);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void CreateEventSource(string source, string logName) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.EventLog.CreateEventSource(System.String,System.String)" />
<MemberSignature Language="VB.NET" Value="Public Shared Sub CreateEventSource (source As String, logName As String)" />
<MemberSignature Language="F#" Value="static member CreateEventSource : string * string -> unit" Usage="System.Diagnostics.EventLog.CreateEventSource (source, logName)" />
<MemberSignature Language="C++ CLI" Value="public:
 static void CreateEventSource(System::String ^ source, System::String ^ logName);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.EventLog</AssemblyName>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="source" Type="System.String" />
<Parameter Name="logName" Type="System.String" />
</Parameters>
<Docs>
<param name="source">The source name by which the application is registered on the local computer.</param>
<param name="logName">The name of the log the source's entries are written to. Possible values include Application, System, or a custom event log.</param>
<summary>Establishes the specified source name as a valid event source for writing entries to a log on the local computer. This method can also create a new custom log on the local computer.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Use this overload to create a custom log or to create and register a <xref:System.Diagnostics.EventLog.Source%2A> to an existing log on the local computer.
If `logName` is `null` or an empty string ("") when you call <xref:System.Diagnostics.EventLog.CreateEventSource%2A>, the log defaults to the Application log. If the log does not exist on the local computer, the system creates a custom log and registers your application as a <xref:System.Diagnostics.EventLog.Source%2A> for that log.
> [!NOTE]
> To create an event source in Windows Vista and later or Windows Server 2003, you must have administrative privileges.
>
> The reason for this requirement is that all event logs, including security, must be searched to determine whether the event source is unique. Starting with Windows Vista, users do not have permission to access the security log; therefore, a <xref:System.Security.SecurityException> is thrown.
>
> In Windows Vista and later, User Account Control (UAC) determines the privileges of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. To execute the code that accesses the security log, you must first elevate your privileges from standard user to administrator. You can do this when you start an application by right-clicking the application icon and indicating that you want to run as an administrator.
You only need to create an event source if you are writing to the event log. Before writing an entry to an event log, you must register the event source with the event log as a valid source of events. When you write a log entry, the system uses the <xref:System.Diagnostics.EventLog.Source%2A> to find the appropriate log in which to place your entry. If you are reading the event log, you can either specify the <xref:System.Diagnostics.EventLog.Source%2A>, or a <xref:System.Diagnostics.EventLog.Log%2A> and <xref:System.Diagnostics.EventLog.MachineName%2A>.
> [!NOTE]
> You are not required to specify the <xref:System.Diagnostics.EventLog.MachineName%2A> if you are connecting to a log on the local computer. If you do not specify the <xref:System.Diagnostics.EventLog.MachineName%2A> when reading from a log, the local computer (".") is assumed.
Use <xref:System.Diagnostics.EventLog.WriteEvent%2A> and <xref:System.Diagnostics.EventLog.WriteEntry%2A> to write events to an event log. You must specify an event source to write events; you must create and configure the event source before writing the first entry with the source.
Create the new event source during the installation of your application. This allows time for the operating system to refresh its list of registered event sources and their configuration. If the operating system has not refreshed its list of event sources, and you attempt to write an event with the new source, the write operation will fail. You can configure a new source using an <xref:System.Diagnostics.EventLogInstaller>, or using the <xref:System.Diagnostics.EventLog.CreateEventSource%2A> method. You must have administrative rights on the computer to create a new event source.
You can create an event source for an existing event log or a new event log. When you create a new source for a new event log, the system registers the source for that log, but the log is not created until the first entry is written to it.
The operating system stores event logs as files. When you use <xref:System.Diagnostics.EventLogInstaller> or <xref:System.Diagnostics.EventLog.CreateEventSource%2A> to create a new event log, the associated file is stored in the %SystemRoot%\System32\Config directory on the specified computer. The file name is set by appending the first 8 characters of the <xref:System.Diagnostics.EventLog.Log%2A> property with the ".evt" file name extension.
The source must be unique on the local computer; a new source name cannot match an existing source name or an existing event log name. Each source can write to only one event log at a time; however, your application can use multiple sources to write to multiple event logs. For example, your application might require multiple sources configured for different event logs or different resource files.
The source must be configured either for writing localized entries or for writing direct strings. If your application writes entries using both resource identifiers and string values, you must register two separate sources. For example, configure one source with resource files, and then use that source in the <xref:System.Diagnostics.EventLog.WriteEvent%2A> method to write entries using resource identifiers to the event log. Then create a different source without resource files, and use that source in the <xref:System.Diagnostics.EventLog.WriteEntry%2A> method to write strings directly to the event log using that source.
To change the configuration details of an existing source, you must delete the source and then create it with the new configuration. If other applications or components use the existing source, create a new source with the updated configuration rather than deleting the existing source.
> [!NOTE]
> If a source has already been mapped to a log and you remap it to a new log, you must restart the computer for the changes to take effect.
## Examples
The following example creates the source `MySource` if it does not already exist, and writes an entry to the event log `MyNewLog`.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic EventLog.CreateEventSource Example/CPP/source.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Diagnostics/EventLog/Overview/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic EventLog.CreateEventSource Example/VB/source.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">
<paramref name="source" /> is an empty string ("") or <see langword="null" />.
-or-
<paramref name="logName" /> is not a valid event log name. Event log names must consist of printable characters, and cannot include the characters '*', '?', or '\\'.
-or-
<paramref name="logName" /> is not valid for user log creation. The event log names AppEvent, SysEvent, and SecEvent are reserved for system use.
-or-
The log name matches an existing event source name.
-or-
The source name results in a registry key path longer than 254 characters.
-or-
The first 8 characters of <paramref name="logName" /> match the first 8 characters of an existing event log name.
-or-
The source cannot be registered because it already exists on the local computer.
-or-
The source name matches an existing event log name.</exception>
<exception cref="T:System.InvalidOperationException">The registry key for the event log could not be opened on the local computer.</exception>
<altmember cref="M:System.Diagnostics.EventLog.DeleteEventSource(System.String)" />
<altmember cref="M:System.Diagnostics.EventLog.SourceExists(System.String)" />
<altmember cref="P:System.Diagnostics.EventLog.Source" />
<altmember cref="P:System.Diagnostics.EventLog.Log" />
<altmember cref="M:System.Diagnostics.EventLog.Delete(System.String)" />
</Docs>
</Member>
<Member MemberName="CreateEventSource">
<MemberSignature Language="C#" Value="public static void CreateEventSource (string source, string logName, string machineName);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void CreateEventSource(string source, string logName, string machineName) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.EventLog.CreateEventSource(System.String,System.String,System.String)" />
<MemberSignature Language="VB.NET" Value="Public Shared Sub CreateEventSource (source As String, logName As String, machineName As String)" />
<MemberSignature Language="F#" Value="static member CreateEventSource : string * string * string -> unit" Usage="System.Diagnostics.EventLog.CreateEventSource (source, logName, machineName)" />
<MemberSignature Language="C++ CLI" Value="public:
 static void CreateEventSource(System::String ^ source, System::String ^ logName, System::String ^ machineName);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.EventLog</AssemblyName>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-6.0;net-7.0;net-8.0;net-9.0;netstandard-2.0;windowsdesktop-6.0;windowsdesktop-7.0;windowsdesktop-8.0;windowsdesktop-9.0">
<AttributeName Language="C#">[System.Obsolete("EventLog.CreateEventSource has been deprecated. Use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead.")]</AttributeName>
<AttributeName Language="F#">[<System.Obsolete("EventLog.CreateEventSource has been deprecated. Use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead.")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1">
<AttributeName Language="C#">[System.Obsolete("This method has been deprecated. Please use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead. http://go.microsoft.com/fwlink/?linkid=14202")]</AttributeName>
<AttributeName Language="F#">[<System.Obsolete("This method has been deprecated. Please use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead. http://go.microsoft.com/fwlink/?linkid=14202")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="windowsdesktop-3.0;windowsdesktop-3.1;windowsdesktop-5.0">