[英]How do I get culture-neutral type information when reading event viewer content with WMI in C#
I am reading logs from EventViewer using below lines of code. 我正在使用下面的代码行从EventViewer中读取日志。
var searcher = new ManagementObjectSearcher(@"\\WS2012-DE01\root\cimv2",
"SELECT * FROM Win32_NTLogEvent WHERE Type ='Error'");
above code works fine in en-US
culture, but will fail in other culture because other culture will be representing Error
as some other word. 上面的代码在
en-US
文化中运作良好,但在其他文化中会失败,因为其他文化将代表Error
作为其他一些词。
eg: Error word in de-DE
culture(german) represents as Fehler . 例如:
de-DE
文化中的错误词(德语)表示为Fehler 。 I will be using the same code in different environement. 我将在不同的环境中使用相同的代码。 I do not want to maintain a resource file since issue is with only one word or not need a Translator API because of security measures to solve this.
我不想维护资源文件,因为问题只有一个字或者不需要翻译API,因为安全措施可以解决这个问题。 Could anyone please provide me a solution.
有谁能请我提供解决方案。
Don't query filtering by the name of the event type, but filtering by the internal type id: 不要按事件类型的名称查询过滤,而是按内部类型id过滤:
var searcher = new ManagementObjectSearcher(@"\\WS2012-DE01\root\cimv2",
"SELECT * FROM Win32_NTLogEvent WHERE EventType=1");
You can see the list of possible values for EventType
in the documentation of the WMI Win32_NTLogEvent class . 您可以在WMI Win32_NTLogEvent类的文档中看到
EventType
的可能值列表。
Note that the property Type
is a string and contains the type in the local language, while EventType
is an integer with a fixed meaning like 请注意,属性
Type
是一个字符串,包含本地语言的类型,而EventType
是一个具有固定含义的整数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.