我正在try 使用log4net在Windows Server 2008 SP1上的IIS7下写入客户事件日志(log).但是,该帐户似乎没有写入事件日志(log)的权限.有人有什么建议吗?
我正在try 使用log4net在Windows Server 2008 SP1上的IIS7下写入客户事件日志(log).但是,该帐户似乎没有写入事件日志(log)的权限.有人有什么建议吗?
问题可能是您的事件源.必须先创建事件源,然后才能写入事件日志(log)(如果不创建,则事件日志(log)对象会在首次写入日志(log)时try "自动"为您创建一个).
您必须拥有更高的权限才能创建事件日志(log)源.在我的一些web应用程序中,我将创建事件源的代码放入了我的设置中(安装程序以管理员身份运行,因此我始终保证能够创建源).
只需创建一次源代码.之后,你的ASP.Net app应有足够的权限写入指定您创建的源的条目.
您可以在设置中使用EventLogInstaller创建源,也可以只编写一个小实用程序以管理员身份调用EventLog.CreateEventSource().
我将向你们展示两种方式:
// You would do this one from within an Installer class in a setup:
private void InstallEventLog()
{
EventLogInstaller logInstaller;
//Create an instance of an EventLogInstaller.
logInstaller = new EventLogInstaller();
//Set the source name of the event log.
logInstaller.Source = "TheEventSourceName";
Installers.Add(logInstaller);
}
方法2:只需以管理员身份调用CreateEventSource一次(例如,您可以将以下代码放入控制台应用程序中,并以管理员身份运行控制台应用程序)
EventLog.CreateEventSource("TheSourceName", "Application");
prize :
[system.Diagnostics.EventLog]::CreateEventSource("SourceName", "Application")
那有帮助吗