简体   繁体   English

将事件日志添加到注册表

[英]add event log to registry

I'm attempting to access a 'ForwardedEvents' events log on a server using 我正在尝试使用服务器访问服务器上的“ForwardedEvents”事件日志

el = new EventLog("ForwardedEvents", serverName);

this isn't working. 这不起作用。

I believe it's not working because the log isn't contained in the registry where Eventlog would expect to find it (HKLM/System/CurrentControlSet/Services/Eventlog/.. ). 我相信它不起作用,因为日志不包含在Eventlog期望找到它的注册表中(HKLM / System / CurrentControlSet / Services / Eventlog / ..)。

How would add the log to registry so it is found, or is there another method to access a log that's not specified in that location? 如何将日志添加到注册表以便找到它,或者是否有另一种方法来访问未在该位置指定的日志?

Remedied the issue by creating a new registry entry for the Log at: (HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\eventlog\\LOGNAME). 通过为Log at:(HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ services \\ eventlog \\ LOGNAME)创建新的注册表项来解决此问题。

Did this by.. ( on windows server 2008 R2 ) .. 这是通过..(在Windows Server 2008 R2上)..

1) Right Click on parent folder (eventlog) -> New -> Key 1)右键单击父文件夹(eventlog) - >新建 - >键

2) Name the key like the evtx file found at (C:\\Windows\\System32\\winevt\\Logs\\LOGNAME) 2)将密钥命名为在(C:\\ Windows \\ System32 \\ winevt \\ Logs \\ LOGNAME)中找到的evtx文件

3) In the right pane of the registry explorer, right click -> new -> Expandable String Value 3)在注册表资源管理器的右窗格中,右键单击 - >新建 - >可扩展字符串值

4) Name the newly created REG_EXPAND_SZ "File" 4)命名新创建的REG_EXPAND_SZ“文件”

5) Right click on the Name "File" 5)右键单击名称“文件”

6) Modify 6)修改

7)In the "Value Data" box, add path to evtx file like 7)在“数值数据”框中,添加evtx文件的路径,如

( %SystemRoot%\\System32\\winevt\\Logs\\ForwardedEvents.evtx ) (%SystemRoot%\\ System32 \\ winevt \\ Logs \\ ForwardedEvents.evtx)

This is close to the other registry solution offered here, but this is how I did it on Windows 7, and will write to the Application log, not the Forwarded Events log: 这与此处提供的其他注册表解决方案很接近,但这是我在Windows 7上执行此操作的方式,并且将写入应用程序日志,而不是Forwarded Events日志:

  • Windows logo > type regedit in the search and press Enter Windows徽标>在搜索中键入regedit ,然后按Enter键

  • Expand HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\eventlog 展开HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\eventlog

  • Find the Application key and create a new key for your application: MyApp 找到Application键并为您的应用程序创建一个新密钥: MyApp

  • In MyApp , right-click the right side window in the blank area and select New > Expandable String Value . MyApp ,右键单击空白区域中的右侧窗口,然后选择“ 新建”>“可扩展字符串值” This will create a REG_EXPAND_SZ entry. 这将创建一个REG_EXPAND_SZ条目。 Give it the name EventMessageFile . 将其命名为EventMessageFile

  • Double-click the new entry to set a value. 双击新条目以设置值。 For the value, enter: C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\EventLogMessages.dll Select OK . 对于该值,请输入: C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\EventLogMessages.dll选择“ 确定”

  • Leave the (Default) string value alone with its (value not set) value. 保留(Default)字符串值,使其(value not set)值。

  • Repeat two more times by replacing CurrentControlSet with ControlSet001 and ControlSet002 . 通过将CurrentControlSet替换为ControlSet001ControlSet002重复两次。

And if you need to then move your application to another computer, you can right-click the key and select Export . 如果您需要将应用程序移动到另一台计算机,则可以右键单击该键并选择“ Export You save the file as a .reg file, and then copy it to the next computer. 您将文件另存为.reg文件,然后将其复制到下一台计算机。 There, you double-click to run it (while logged in as an Administrator). 在那里,双击运行它(以管理员身份登录)。 In this way, you don't have to manually re-create it, and for other apps, you can actually edit the .reg file in Notepad and simply change the name of the app, save it (be sure to change the format to "All Files", so it retains the .reg on the end, and not save it as a .txt file), and then you can double-click it to run and insert the new app's EventLog key. 通过这种方式,您不必手动重新创建它,对于其他应用程序,您可以在记事本中实际编辑.reg文件,只需更改应用程序的名称,保存即可(请务必将格式更改为“所有文件”,因此它在末尾保留.reg ,而不是将其保存为.txt文件),然后您可以双击它以运行并插入新应用程序的EventLog键。

If you still want to do this the programmatic way as opposed to manually creating the log via the registry, there is a way. 如果您仍然希望以编程方式执行此操作,而不是通过注册表手动创建日志,则有一种方法。 You need to check and see if the EventSource exists first, and if it doesn't you need to create it. 您需要先检查并查看EventSource存在,如果不存在则需要创建它。 This has to happen all before you try to create an EventLog instance with that source. 这必须在您尝试使用该源创建EventLog实例之前发生。 Just note the latency between creation and use, so make sure to handle this (see http://msdn.microsoft.com/en-us/library/2awhba7a(v=vs.110).aspx for more information). 请注意创建和使用之间的延迟,因此请务必处理此问题(有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/2awhba7a(v=vs.110).aspx )。

// Create the source, if it does not already exist. 
if(!EventLog.SourceExists("MySource"))
{
    //An event log source should not be created and immediately used. 
    //There is a latency time to enable the source, it should be created 
    //prior to executing the application that uses the source. 
    //Execute this sample a second time to use the new source.
    EventLog.CreateEventSource("MySource", "MyNewLog");
    Console.WriteLine("CreatedEventSource");
    Console.WriteLine("Exiting, execute the application a second time to use the source.");
    // The source is created.  Exit the application to allow it to be registered. 
    return;
}

// Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "MySource";

// Write an informational entry to the event log.    
myLog.WriteEntry("Writing to event log.");

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

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