简体   繁体   English

如何使用System.Diagnostics.EventLog从任意evxt文件读取?

[英]How do I read from an arbitrary evxt file using System.Diagnostics.EventLog?

How can I use EventLog to read from an arbitrary evtx file? 如何使用EventLog读取任意evtx文件?

EventLogQuery is able to open evtx files, but it is not available in .NET 2.0. EventLogQuery能够打开evtx文件,但在.NET 2.0中不可用。

Let's assume the log file is LogA.evtx . 假设日志文件是LogA.evtx

Copy LogA.evtx to C:\\Windows\\System32\\winevt\\Logs . LogA.evtx复制到C:\\Windows\\System32\\winevt\\Logs

Add a new registry key to: 将新的注册表项添加到:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog

called LogA . 称为LogA Eg in PowerShell: 例如在PowerShell中:

Set-Location HKLM:

New-Item .\SYSTEM\CurrentControlSet\services\eventlog -Name LogA

Open Event Viewer to verify that LogA shows up under Applications and Services Logs . 打开事件查看器以验证LogA是否显示在“ 应用程序和服务日志”下

You can now open LogA using EventLog : 您现在可以使用EventLog打开LogA

using System;
using System.Diagnostics;

namespace EventLogTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var log = new EventLog("LogA");

            Console.WriteLine(log.Entries.Count);
        }
    }
}

You can delete LogA via PowerShell: 您可以通过PowerShell删除LogA

[System.Diagnostics.EventLog]::Delete("LogA")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM