【发布时间】:2015-10-25 15:00:06
【问题描述】:
我在 PowerShell 函数(名为 Create-EventLog)中有以下代码 (sn-p)。最终结果应该如下:
- 名为
Get-Drives的新事件日志是 PowerShell 写入此应用程序的所有异常消息。Get-Drives事件日志被创建但出于某种原因 实际消息只会写入默认的Windows PowerShell事件日志。如何让 PowerShell 将消息写入“Get-Drives”事件日志而不是“Windows PowerShell”事件日志?我正在使用 PowerShell 4 并在 Visual Studio 2013 中使用 PowerShell 工具。
我的 PowerShell 函数 sn-p:
if (!$EventLogExists) {
New-EventLog -LogName "Get-Drives" -source "Get-Drives"
Write-EventLog -LogName "Get-Drives" -source "Get-Drives" -EventId 1 -message "There was an error"
return
} else {
Write-EventLog -LogName "Get-Drives" -source "Get-Drives" -EventId 1 -message "There was an error"
return
}
运行Get-EventLog -List 显示以下输出:
在条目下,Get-Drives 日志的值为 1,但它仅显示在 Windows Powershell 日志中,该日志的值也为 1。
事件查看器的屏幕截图
【问题讨论】:
标签: .net visual-studio powershell