log4Net EventlogAppender does not work for Asp.Net 2.0 WebSite?

前端 未结 3 1140
情歌与酒
情歌与酒 2020-12-19 02:47

I have configured log4Net EventLogAppender for Asp.Net 2.0. However it does not log anything. I have following in my Web.Config.


    

        
3条回答
  •  遥遥无期
    2020-12-19 03:37

    There's some very simple steps to get Log4Net working with the event log with ASP.NET.

    Your options are:

    Change the app pool

    Run the application pool as LocalSystem

    Or...set an application name, add a registry key

    Configure your config file first so there is an application name.

    This is important if you are having a permissions issue, because if you peer at the source you'll see the EventLogAppender defaults the application name (the source column in the event log) to:

    System.Threading.Thread.GetDomain().FriendlyName

    This requires your application to create a registry key each time the name changes, and is a bit messy. So the best solution is to set your application name. Here's an example EventLogAppender section that sends every error level, the ApplicationName line is the important part:

    
        
        
            
        
        
            
            
        
        
            
            
        
    
    

    Before making this change, do the following:

    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

    C:\Windows\Microsoft.NET\Framework\v2.0.50727\EventLogMessages.dll

    That path appears to work in both 64 bit and 32 bit environments.

    With this technique you don't need to set permissions in the registry, and once the key above is created it should just work.

提交回复
热议问题