我正在使用以下行创建新的事件日志
new-eventlog -LogName "Visual Studio Builds" -Source "Visual Studio"
我想每次都运行它,因为如果我从新计算机运行构建,我仍然希望查看事件日志。
问题是,每次在创建日志后运行脚本时,都会抛出错误。
New-EventLog : The "Visual Studio" source is already registered on the "localhost" computer.
At E:\Projects\MyApp\bootstrap.ps1:14 char:13
+ new-eventlog <<<< -LogName "Visual Studio Builds" -Source "Visual Studio"
+ CategoryInfo : InvalidOperation: (:) [New-EventLog], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.NewEventLogCommand
现在我知道我可以“搜索”事件日志
Get-EventLog -list | Where-Object {$_.logdisplayname -eq "Visual Studio Builds"}
但现在我如何确定它是否存在呢?
# Check if Log exists
# Ref: http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.exists(v=vs.110).aspx
[System.Diagnostics.EventLog]::Exists('Application');
# Ref: http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.sourceexists(v=vs.110).aspx
# Check if Source exists
[System.Diagnostics.EventLog]::SourceExists("YourLogSource");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)