How to write an event log

As you know, we can use the EventLog class to write event logs, but I'm confused about how to write the category name to the event log. Thoug provides a category parameter, for example, one of the WriteEntry types:

public void WriteEntry( string message, EventLogEntryType type, int eventID, short category 

)
And he just shows the number in my journal. Why is the category type short and not string? How to display category name in event viewer? Thank you By the way, we will not create a custom CategoryMessageFile.

+6
source share
3 answers

You can write an entry in the event log with the specified category, but you need to create an additional custom dll with the String Resource table, which is registered in the event log. This complicates your deployment further. You currently have to do during installation

  1. To create new event log sources, you need to have administrator rights every time you create a new source. Therefore, it is advisable to collect all the sources so that you can install them immediately during the initial installation.
  2. Create your own dll that contains the String Resource table for each category that you want to specify.
  3. Register the dll categories in the registry so that Windows knows about it.

Now you can use overloading to write an event log message with a given category.

There is a very good article in the journal Dr. Jobs Journal, which accurately describes your issue.

+5
source

Do not use WriteEntry, you will get a security exception. Administrator rights are not required after installation.

Use WriteEvent instead: https://security.stackexchange.com/q/15857/396

0
source

you have so many overloads - which can satisfy you: (why do you choose complex ones? :))

the category is used to filter events in the event log (which you can also use with the source attribute)

enter image description here

use the first or second.

Edit

 EventLog.CreateEventSource("MyWebApplication", "Application") ; 
-1
source

Source: https://habr.com/ru/post/915008/


All Articles