windows - 如何使用 Write-EventLog 在事件日志中显示任务类别的字符串名称?

标签 windows events powershell logging

因此,我尝试使用 Write-EventLog 写入 Windows 事件日志。我编译了一个 CategoryMessageFile .dll 并在注册表中注册了它。

我的脚本大部分写入事件日志,但问题是事件不显示类别名称;它显示在 dll 中枚举的类别消息 ID。

New-EventLog -LogName Application -Source 'test1' -CategoryResourceFile 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\test.dll'

Write-EventLog -LogName Application -Source 'test1' -EntryType Information -EventId 1 -Message "$($DataSet.Tables[0].Rows[$i][6])" -Category 1

I know the mapping is correct because when I run

Get-EventLog -LogName Application -Newest 3 | Format-List

The correct Category name shows up under Category for the events I had just written to the log.

Here is what my mc file looked like.

;// Header


;// Categories
MessageIdTypedef=WORD

MessageId=0x1
Language=English
ETLUncategorizedError
.

MessageId=0x2
Language=English
ETLThresholdExceeded
.

MessageId=0x3
Language=English
ETLMalformattedFile
.

MessageId=0x4
Language=English
ETLWebInvocationFailure
.

那么,如何在事件日志中显示名称而不是数字?

最佳答案

您可能正在应用程序或系统日志事件中查找它,并且您运行的第一个命令创建了一个名为 TEST1 的日志。

描述 此 cmdlet 在本地或远程计算机上创建新的经典事件日志。它还可以注册一个事件源,该事件源写入新日志或 现有日志。

关于windows - 如何使用 Write-EventLog 在事件日志中显示任务类别的字符串名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17934357/

相关文章:

c++ - 在 C++ 中使用 UTF-8 std::string 对象

mysql - Ruby 1.9 + MySQL 访问错误

c++ - onTouchBegan 不工作 cocos2dx

powershell - 使用powershell创建事件日志条目并填写用户

windows - 删除文件名开头至 "_"

windows - Pickled Matplotlib 3D 缺乏交互功能

Delphi Web Script (DWScript) 将脚本方法链接到外部控件事件

javascript - Jquery 后期绑定(bind)使用 on - 旧表单不起作用?

powershell - 查找模式之间的行,并将第一行附加到行中

azure - 从 DevOps 管道中的服务主体生成 SAS token (自托管)