2

我正在尝试在 Azure 函数中读取导出的 evtx 事件日志文件。我将文件内容作为字节数组接收,然后写入临时文件。然后我尝试从 Microsoft.Extensions.Logging.EventLog 包中创建 EventLogReader 的实例,如下所示:

       string tempfile = Path.GetTempFileName();
       string fileout = Path.ChangeExtension(tempfile, ".evtx");
       File.WriteAllBytes(fileout, eventLogData);
       var eventLog = new EventLogReader(fileout, PathType.FilePath);

EventLogReader 失败并出现以下异常:

System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
   at System.Diagnostics.Eventing.Reader.EventLogException.Throw(Int32 errorCode)
   at System.Diagnostics.Eventing.Reader.NativeWrapper.EvtQuery(EventLogHandle session, String path, String query, Int32 flags)
   at System.Diagnostics.Eventing.Reader.EventLogReader..ctor(EventLogQuery eventQuery, EventBookmark bookmark)

有没有办法解决这个问题,因为我认为它不需要额外的用户权限来从文件中读取事件日志,因此可以从 Azure 函数中使用?如果没有,有没有办法直接从流而不是文件路径中读取 evtx 文件?

4

0 回答 0