Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write event log category

As we know, we can use the class EventLog to write event logs, but I am confused about how to write category name in my event log. Thoug it provides the category parameter, for example, one of the type of WriteEntry is:

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

)
And it just shows number in my log. Why the type of category is short, not string? How to display the category name in the Event Viewer? Thanks! By the way, we will not create the custom CategoryMessageFile.

like image 780
Xiaodan Mao Avatar asked May 06 '12 08:05

Xiaodan Mao


People also ask

What are the categories in Event Viewer?

They are Information, Warning, Error, Success Audit (Security Log) and Failure Audit (Security Log).

What cmdlet might you use to write to an event log?

The Write-EventLog cmdlet writes an event to an event log. To write an event to an event log, the event log must exist on the computer and the source must be registered for the event log.

What are the 5 level events the Event Viewer shows?

Windows uses the following levels: Critical, Error, Warning, Information, Verbose (although software developers may extend this set and add own specific levels).


1 Answers

You can write an event log entry with a given category but you need to create an extra native dll with a String Resource table which is registered in the event log. This does complicate your deployment further. You currently have to do during installation

  1. To create new Event Log Sources you need to have admin rights every time you create a new source. It is therefore wise to collect all sources so you can install at once during the initial installation.
  2. Create a native dll which does contain a String Resource table for each category id you want to supply.
  3. Register the category dll in the registry to make Windows aware of it.

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

There is a very good Dr. Jobs Journal article describing exactly your problem.

like image 173
Alois Kraus Avatar answered Nov 11 '22 22:11

Alois Kraus