【问题标题】:new event log is linked to application event log新事件日志链接到应用程序事件日志
【发布时间】:2015-03-09 19:30:06
【问题描述】:

我正在使用 Powershell v3.0

我正在尝试创建新的事件日志。 当我创建事件日志时,它似乎是应用程序日志的副本。

  • 新日志中包含所有应用程序日志消息,

  • 写入应用程序日志的新事件会同时显示,

  • 写入新日志的新事件同时显示,

  • 如果我删除新的事件日志,应用程序日志内容是 已删除(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
}

【问题讨论】:

  • 好的,问题的一部分似乎是范围问题。当我重新启动其中一台出现问题的服务器时,我能够 Remove-EventLog "OpsBrain" 然后 New-EventLog -LogName "OpsBrain" 按预期工作。我仍然不确定我首先做了什么导致它链接到应用程序日志。

标签: powershell logging


【解决方案1】:

如果我也这样做:

$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 Test

【讨论】:

  • $EventLogName = "OpsBrain"; $EventLogSource="OpsBrainService"
  • 我已经扩展了我的答案。你能在上面检查一下吗?
  • 清除以前的尝试后,我的应用程序日志中有 0 个事件。我添加了一个事件。然后我运行了你发布的代码。我现在有一个 OpsBrain 事件日志,其中包含一个事件。也就是说,它再次克隆了应用程序日志。但至少我知道它在“某处”按设计工作。它一定是我的环境中的东西。
  • 是否可以发布更多代码?也许还有其他问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-22
  • 2014-11-01
  • 2021-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多