C# 正在尝试将事件日志文件复制到另一个文件夹以进行备份

C# 正在尝试将事件日志文件复制到另一个文件夹以进行备份,c#,copy,event-log,C#,Copy,Event Log,我试图将事件日志“应用程序”复制到我电脑上的另一个文件夹,但总是出现以下错误: “…找不到路径的一部分 'C:\Windows\System32\winevt\Logs\Application.evtx…” 我使用代码: public void collectEventLogsFromSystem(string RequestedlogName,string newFolderPath) { string combinedLogToFind = "HKEY_LOCAL_MACH

我试图将事件日志“应用程序”复制到我电脑上的另一个文件夹,但总是出现以下错误:

“…找不到路径的一部分 'C:\Windows\System32\winevt\Logs\Application.evtx…”

我使用代码:

public void collectEventLogsFromSystem(string RequestedlogName,string newFolderPath)
{
    string combinedLogToFind =      "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Eventlog\\" + RequestedlogName;
    string LogEventsPath = (string)Registry.GetValue(combinedLogToFind, "File", null);
    if (LogEventsPath != null)
    {
        System.IO.File.Copy(LogEventsPath, newFolderPath +"\\"+ RequestedlogName, true);               
    }

}//collectEventLogsFromSystem method
即使我使用显式文件夹路径,它也无法工作:

System.IO.File.Copy(@"C:\Windows\System32\winevt\Logs\Application.evtx", "c:\\ttt\\Application.evtx", true);

有什么想法吗?

我在StackOverflow上找到了这个答案,它可能会解决您的问题。我有一台64位的机器,它表现出同样的行为。John Rasch的这篇文章解决了这个问题,并解释了它失败的原因。

如果您试图在程序运行时获取日志文件,上述方法将不起作用。这篇文章将允许您备份事件日志,即使您当前正在应用程序中使用事件日志