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.
They are Information, Warning, Error, Success Audit (Security Log) and Failure Audit (Security 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.
Windows uses the following levels: Critical, Error, Warning, Information, Verbose (although software developers may extend this set and add own specific levels).
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With