c# - 使用powershell设置事件日志 "Maximum Size"操作

标签 c# powershell event-log

查看事件日志属性(在 Server 2008 中)时,您可以设置三个操作,以设置在达到最大事件日志大小时发生的情况:

  • 根据需要覆盖事件
  • 日志满时存档
  • 不要覆盖事件

使用 Powershell 我可以使用 limit-eventlog设置事件日志保留,将 OverflowAction 设置为 DoNotOverwrite 或 OverwriteAsNeeded,但我似乎无法获得选择的Archive the log when full 操作。

有什么想法可以通过 powershell 选择此选项吗?

最佳答案

唯一的方法(IMO)是修改注册表。以下是为应用程序日志设置“日志满时存档”操作的示例:

new-ItemProperty -path HKLM:\SYSTEM\CurrentControlSet\services\eventlog\Application `
-name AutoBackupLogFiles -Value 1 -PropertyType 'dword'

如果之前已选择选项,则 key 已经存在,因此只需将 key 值设置为 1:

set-ItemProperty -path HKLM:\SYSTEM\CurrentControlSet\services\eventlog\Application `
    -name AutoBackupLogFiles -Value 1 

关于c# - 使用powershell设置事件日志 "Maximum Size"操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12628708/

相关文章:

.net - 编写事件日志条目的最佳方法是什么?

c# - 为什么 ItemCollection.Groups 是对象的集合而不是 CollectionViewGroups?

c# - PropertyGrid,设计者与运行时的行为有何不同?

c# - BackgroundWorker 的底层是如何工作的?

c# - 对 SSPI 的调用失败,请参阅内部异常 - 无法联系本地安全机构

bash - Bash 上的反勾号的 cmd/PowerShell 等价物是什么?

powershell - 如何从Powershell打开命令提示符

powershell - PowerShell:如何将黑名单作为Get-ChildItem -Exclude标志的命令参数传递

powershell - 变量中具有多个ID的Get-WinEvent -FilterHashTable不起作用

c++ - 查询事件日志。如何查询以单独获取第一个和最后一个事件?