写在Windows Server 2008上的IIS7的事件日志中ASP.NET [英] Writing to an event log in ASP.NET on Windows Server 2008 IIS7

查看:145
本文介绍了写在Windows Server 2008上的IIS7的事件日志中ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用log4net的写入的Windows Server 2008 SP1 IIS7下一个客户事件日志。但是,帐户似乎没有能够获得写入到事件日志。有没有人有什么建议?

I'm trying to use log4net to write to a customer event log under IIS7 on Windows Server 2008 SP1. However, account doesn't seem to have access to write to the event log. Does anyone have any suggestions?

推荐答案

该问题可能是您的事件源。你必须创建一个事件源之前,你可以写信给事件日志(如果你不这样做,事件日志对象尝试为您创建一个自动的你第一次写入日志)。

The problem is probably your event source. You have to create an event source before you can write to the event log (if you don't, the Event log object tries to create one for you "automagically" the first time you write to the log).

您已经hightened权限创建一个事件日志源。在我的一些网络应用程序,我已经把code创建事件源进入我的设置(设置运行作为管理员,所以我总是保证能够创建源)。

You have to have hightened permissions to create an event log source. In some of my web apps, I have put the code to create the event source into my setup (setup runs as admin, so I'm always guaranteed to be able to create the source).

您只需要一次创建源。在这之后,你的ASP.Net应用程序应该有足够的权限来写条目指定源(或来源),您创建的。

You just have to create the source once. After that, your ASP.Net app should have sufficient permissions to write entries specifying the source (or sources) that you created.

您可以使用EventLogInstaller在您的设置创建源,或者你可以只写一个小程序来调用EventLog.CreateEventSource()作为一个管理员。

You can use an EventLogInstaller in your setup to create the source, or you could just write a little utility to call EventLog.CreateEventSource() as an admin.

我会告诉你两种方式:



// 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作为管理员(你可以把下面的code到一个控制台应用程序,例如,然后运行控制台应用程序作为管理员

Method 2: just call CreateEventSource once as an admin (you could put the following code into a console app, for example, and run the console app as admin



EventLog.CreateEventSource("TheSourceName", "Application");

奖励:
如果您已经在服务器上安装PowerShell中,你可以从PowerShell命令提示符下做到这一点:
(请确保您正在运行PowerShell的作为管理员)

Bonus: If you have Powershell installed on your server, you can do it from the Powershell command prompt: (Make sure you are running Powershell as an admin)



[system.Diagnostics.EventLog]::CreateEventSource("SourceName", "Application")

合,帮助

这篇关于写在Windows Server 2008上的IIS7的事件日志中ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆