我正在使用Powershell v3.0
我正在尝试创建一个新的事件日志。创建事件日志时,它似乎是应用程序日志的副本。
下面是创建新事件日志的代码:
#Add Event Log if not already added
$CheckEL = @(Get-EventLog -List | Where-Object {$_.Log -eq $EventLogName})
if($CheckEL.Count -eq 0){
if ([System.Diagnostics.EventLog]::SourceExists($EventLogSource)){
[System.Diagnostics.EventLog]::DeleteEventSource($EventLogSource)
}
New-EventLog -LogName $EventLogName -Source $EventLogSource -ErrorAction Stop
Limit-EventLog -LogName $EventLogName -OverflowAction OverWriteAsNeeded -MaximumSize 64KB
}发布于 2015-03-06 15:28:49
如果我这么做的话:
$EventLogName = "OpsBrain";
$EventLogSource="OpsBrainService"
#Test if Event Log not already exists
$CheckEL = @(Get-EventLog -List | Where-Object {$_.Log -eq $EventLogName})
if($CheckEL.Count -eq 0){
#Event Log does not yet exists, create it:
New-EventLog -LogName $EventLogName -Source $EventLogSource
}然后将一些内容写入事件日志(否则无法检索日志文件的内容):
Write-EventLog OpsBrain -Source $EventLogSource -EventId 1 -Message "Test"然后我只检索到一个对象:
Get-EventLog OpsBrain
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
1 mrt 09 12:26 Information OpsBrainService 1 Testhttps://stackoverflow.com/questions/28866093
复制相似问题