How to get culture neutral type information while reading Event Viewer content using WMI in C #
I am reading logs from EventViewer using the below lines of code.
var searcher = new ManagementObjectSearcher(@"\\WS2012-DE01\root\cimv2",
"SELECT * FROM Win32_NTLogEvent WHERE Type ='Error'");
the above code works great in culture en-US
, but will fail in another culture because the other culture will represent it Error
as some other word.
eg: Error word in de-DE
culture (German) presents as Fehler . I will use the same code under different conditions. I don't want to maintain a resource file as the issue is one word or doesn't need the Translator API due to security measures to resolve this issue. Can anyone suggest me a solution.
source to share
Don't request filtering by event type name, but filter by internal type ID:
var searcher = new ManagementObjectSearcher(@"\\WS2012-DE01\root\cimv2",
"SELECT * FROM Win32_NTLogEvent WHERE EventType=1");
You can view the list of possible values EventType
in the documentation for the WMI Win32_NTLogEvent class .
Note that the property Type
is a string and contains a type in the local language and EventType
is a fixed value integer, like
- 1 = Error
- 2 = Warning
- 3 = Information
- 4 = Success of security audit
- 5 = Security check failed
source to share