开发者

eventlog not working in an asp.net application

from an ASP.Net 3.5 web application, I'm trying to log messages to the Windows EventLog.

I first tried with the En开发者_Python百科tLib Logginh block, but when this failed I tried with the EventLog class directly. It failed too. They do not throw any exception... the just don't write the message. EntLib did write the message to a file, but not to the Windows EventLog.

Here is my code:

public static void LogMessage(string title, string message){

        //EventLog log = new EventLog();
        //log.Source = LOG_SOURCE;
        //log.WriteEntry(message, EventLogEntryType.Error);

        //EventLog.WriteEntry(LOG_SOURCE, message);

        LogWriter writer = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
        writer.Write(message);
    }

I create the log & source in an installer class. Let me know if I should place that code here. The log is created correctly, since I can see it in the EventViewer. The source is created correctly, since I can see it in the "EventLog\MyLog" folder at the regedit.

I've been reading and there is an article stating following line could help:

EventLogPermission perm = new EventLogPermission(EventLogPermissionAccess.Administer, ".");

            perm.PermitOnly();

but it didn't.

If it helps, my code structure is as follows:

  1. Class library project (here is the LogMessage method)
  2. Class Library project (here are the methods which catch exceptions and call LogMessage)
  3. ASP Net web application project (web pages. This layer calls layer #2. Here is my installer class too)
  4. Web setup project (this has custom actions pointing to web setup project output)

Could you please help to figure out what's happening???

Thanks

I found the following resource: "http://www.netframeworkdev.com/net-base-class-library/trouble-writing-to-eventlog-16723.shtml", so it seems it is not possibly to create custom logs from ASP... still investigating


Try giving the Network Service account the appropriate permissions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜