简体   繁体   English

我如何使用C#写入Windows事件日志(我遇到某种错误)?

[英]How can i write to the windows event log using C# (I'm getting some kind of error)?

I have written: 我已经写了:

.
.
.
//Log exception to the event log
if (!EventLog.SourceExists("PodaHIS")) {
    EventLog.CreateEventSource("PodaHIS", "Application");   
}

EventLog eventLog = new EventLog();
eventLog.Log = "Application";
eventLog.Source = "PodaHIS";
eventLog.WriteEntry(error.ToString(), EventLogEntryType.Error);

I have also enabled read permission to LOCALMACHINE\\ASPNET. 我还启用了对LOCALMACHINE \\ ASPNET的读取权限。

And in return i get: 作为回报,我得到:

The source was not found, but some or all event logs could not be searched. Inaccesible logs: Security.

Does anyone know why this is happening? 有人知道为什么会这样吗?

HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\EventLog HKEY_LOCAL_MACHINE \\ System \\ CurrentControlSet \\ Services \\ EventLog

What is need to do was grant the " Security " sub key of the EventLog Key read permission. 需要做的是授予EventLog Key读取权限的“ Security ”子密钥。 After that i restarted my IIS. 之后,我重新启动了IIS。

如果您在要向其中写入事件日志的框上具有权限,则可以运行我编写的脚本

this kb artical explains the steps required to give your asp process the correct security rights to write to the event log... 这篇kb的文章解释了赋予您的asp进程正确的安全权限以写入事件日志的步骤...

kb 千位

I think that a higher level of access is required to create a source in the event log. 我认为在事件日志中创建源需要更高级别的访问。 It's possible that the reference to Security log is coincidental and it is just reporting that as a possible cause. 对安全日志的引用可能是偶然的,它只是在报告可能的原因。 If you go in as an administrator and create the PodaHIS source yourself, you might then find that it can write to it. 如果您以管理员身份创建自己的PodaHIS源,则可能会发现它可以对其进行写入。

What it your deployment environment? 您的部署环境是什么? If it is Vista/Server 2008 then adding worker account into Administrators group won't work due to UAC. 如果是Vista / Server 2008,则由于UAC无法将工作人员帐户添加到Administrators组中。

This link explains the problem in details. 链接详细说明了该问题。 But I would recommend try creating an event source manually so ASPNET won't need to create it... 但我建议尝试手动创建事件源,以便ASPNET无需创建它。

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

相关问题 C# Unity JsonUtility,我怎样才能把这个简单的 json 变成某种有用的 c# ZA8CFDE6331BD59EB2ACZ66F666 - C# Unity JsonUtility, how can I turn this simple json into some kind of useful c# object? 我如何知道我在Windows Mobile中使用C#使用的是固定IP还是DHCP - How can I know if I'm using Fixed IP or DHCP in windows mobile using C# 我正在使用C#,缺少Windows Store App模板,该如何解决? - I'm using C#, Windows Store App template is missing, how can I fix this? 尝试在Visual C#中添加新连接时,如何解决事件日志已满错误? - How can I resolve the event log full error upon attempting to add a new connection in Visual C#? 我如何在c#中等待一段时间(Windows服务) - How I can waiting some time in c# (windows service) 如何使用 c# 和 WPF 编写 windows 7 桌面小工具? - How can I write windows 7 desktop gadgets using c# & WPF? 我应该多久写入一次Windows中的事件日志? - How often should I write to the Event Log in Windows? UWP C#如何写入事件日志 - UWP C# How to Write to Event Log 我如何在C#中拥有一种虚拟静态成员 - How can I have a kind of virtual static member in c# 我如何通过特定来源获取 windows 事件日志列表 C# - How do i get windows event log list by specific source C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM