简体   繁体   English

我需要更改以允许我的IIS7 ASP.Net 3.5应用程序创建事件源并将事件记录到Windows EventLog?

[英]What do I need to change to allow my IIS7 ASP.Net 3.5 application to create an event source and log events to Windows EventLog?

ASP.Net 3.5 running under IIS 7 doesn't seem to allow this out of the box. 在IIS 7下运行的ASP.Net 3.5似乎不允许开箱即用。

        if (!EventLog.SourceExists("MyAppLog"))
            EventLog.CreateEventSource("MyAppLog", "Application");

        EventLog myLog = new EventLog();
        myLog.Source = "MyAppLog";
        myLog.WriteEntry("Message");

I've copied this answer from here (the question was Log4Net but the answer still applies). 我从这里复制了这个答案(问题是Log4Net,但答案仍然适用)。 The technet link misses a vital step. technet链接错过了至关重要的一步。

Create a registry key 创建一个注册表项

HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\eventlog\\Application\\MY-AWESOME-APP

Create a string value inside this 在此内部创建一个字符串值

Name it EventMessageFile , set its value to 将其命名为EventMessageFile ,将其值设置为

C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\EventLogMessages.dll C:\\ WINDOWS \\ Microsoft.NET \\框架\\ V2.0.50727 \\ EventLogMessages.dll

That path appears to work in both 64 bit and 32 bit environments. 该路径似乎适用于64位和32位环境。

With this technique you don't need to set permissions in the registry, and once the key above is created it should just work. 使用此技术,您无需在注册表中设置权限,并且一旦创建了上面的密钥,它就可以正常工作。

Alternatively 另外
If you don't have a large server farm but just a small "web garden" you could run a console application on each server that creates the event log source using EventLog.CreateEventSource , make sure the console application is run by an administrator. 如果您没有大型服务器场但只有一个小型“Web园”,则可以在使用EventLog.CreateEventSource创建事件日志源的每台服务器上运行控制台应用程序,确保控制台应用程序由管理员运行。

This is part of windows security since windows 2003. 从Windows 2003开始,这是Windows安全性的一部分。

You need to create an entry in the registry under HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application Make sure that network service or the account you impersonate has permission to this registry key. 您需要在HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ Services \\ Eventlog \\ Application下的注册表中创建一个条目确保网络服务或您模拟的帐户具有此注册表项的权限。

@CheGueVerra's link: Requested Registry Access Is Not Allowed @ CheGueVerra的链接: 不允许请求的注册表访问

右键单击该应用程序并选择“以管理员身份运行”

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

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