ASP.Net 3.5 running under IIS 7 doesn't seem to allow this out of the box.
ASP。在iis7下运行的Net 3.5似乎不允许这样做。
if (!EventLog.SourceExists("MyAppLog"))
EventLog.CreateEventSource("MyAppLog", "Application");
EventLog myLog = new EventLog();
myLog.Source = "MyAppLog";
myLog.WriteEntry("Message");
3 个解决方案
#1
23
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\系统\CurrentControlSet\Services\Eventlog应用程序的注册表中创建一个条目,以确保您模拟的网络服务或帐户具有此注册表项的权限。
@CheGueVerra's link: Requested Registry Access Is Not Allowed
@CheGueVerra的链接:请求的注册表访问是不允许的
#2
30
I've copied this answer from here (the question was Log4Net but the answer still applies). The technet link misses a vital step.
我从这里复制了这个答案(问题是Log4Net,但答案仍然适用)。technet链接漏掉了一个关键步骤。
Create a registry key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MY-AWESOME-APP
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ \应用程序事件日志\ \ 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 \ Framework \ 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,确保控制台应用程序由管理员运行。
#3
1
Right click the application and choose "Run as Administrator"
右键单击应用程序并选择“作为管理员运行”
#1
23
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\系统\CurrentControlSet\Services\Eventlog应用程序的注册表中创建一个条目,以确保您模拟的网络服务或帐户具有此注册表项的权限。
@CheGueVerra's link: Requested Registry Access Is Not Allowed
@CheGueVerra的链接:请求的注册表访问是不允许的
#2
30
I've copied this answer from here (the question was Log4Net but the answer still applies). The technet link misses a vital step.
我从这里复制了这个答案(问题是Log4Net,但答案仍然适用)。technet链接漏掉了一个关键步骤。
Create a registry key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MY-AWESOME-APP
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ \应用程序事件日志\ \ 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 \ Framework \ 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,确保控制台应用程序由管理员运行。
#3
1
Right click the application and choose "Run as Administrator"
右键单击应用程序并选择“作为管理员运行”