You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Matthew Brown <oc...@gmail.com> on 2005/10/10 22:42:44 UTC

Inability to use EventLogAppender with ASPNET

With log4net internal debugging turned on, an attempt to create an
EventLogAppender for a web application is failing:

[3616] log4net: XmlHierarchyConfigurator: Setting Property [Layout] to
object [log4net.Layout.PatternLayout]
[3616] log4net: XmlHierarchyConfigurator: Setting Property [LogName] to
String value [Application]
[3616] log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[EventLog] of type [log4net.Appender.EventLogAppender]. Reported error
follows.
[3616] System.Security.SecurityException: Requested registry access is not
allowed.
[3616] at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean
writable)
[3616] at System.Diagnostics.EventLog.FindSourceRegistration(String source,
String machineName, Boolean readOnly)
[3616] at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
[3616] at System.Diagnostics.EventLog.SourceExists(String source)
[3616] at log4net.Appender.EventLogAppender.ActivateOptions()
[3616] at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
appenderElement)
[3616] log4net:ERROR XmlHierarchyConfigurator: Appender named [EventLog] not
found.
[3616] log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
[3616] log4net: AppenderSkeleton: Finalizing appender named [EventLog].

The FAQ on the log4net site says that the ASPNET account has permission to
write to the event log if created already. Just to be sure, I made sure to
add ASPNET and IUSR_machinename to the Administrators group, but this does
not work either.

Here is my configuration:

<appender name="EventLog" type="log4net.Appender.EventLogAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread][%mdc{AspNetSessionID}] %-5level
%logger - %message%newline" />
</layout>
<logName value="Application"/>
</appender>

<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="EventLog" />
</root>

Sorry if this is a silly newbie question, but I couldn't find much out there
on configuring/using EventLogAppender besides "its tough". Can anyone help?

Thanks,
Matt Brown

Re: Inability to use EventLogAppender with ASPNET

Posted by Ron Grabowski <ro...@yahoo.com>.
m_applicationName = System.Threading.Thread.GetDomain().FriendlyName;

I don't believe this is documented anywhere.

--- Matthew Brown <oc...@gmail.com> wrote:

> What event source is used by default if no ApplicationName is
> supplied?
> 
> On 10/12/05, Billy Barnum <b....@comcast.net> wrote:
> > I agree, should be added to FAQ. There's a MS artcicle here:
> > http://support.microsoft.com/default.aspx?scid=kb;en-us;329291.
> >
> > But you don't NEED to hack the registry. If it's a problem for you,
> just
> > remove the LogName and ApplicationName elements from your corn-fig
> file and
> > you should run out-of-the-box. It's been a little while, but I
> believe I ran
> > that way at first. Of course, you won't get to have that
> ApplicationName
> > element jam something nice that you want into the 'Source' field in
> the
> > EventLog, but if access to the registry is a problem, ...
> >
> > -BillyB
> >
> > -----Original Message-----
> > From: Matthew Brown [mailto:octavius@gmail.com]
> > Sent: Wednesday, October 12, 2005 5:53 AM
> > To: Log4NET User
> > Subject: Re: Inability to use EventLogAppender with ASPNET
> >
> > Adding permission explicitly to the EventLog key (and all
> > subkeys) seems to have done the trick.
> >
> > Maybe this should be added to the FAQ... :)
> >
> > On 10/11/05, Hollywood <ho...@thzero.com> wrote:
> > > I've been running into this lately.  One of the items is to make
> sure your
> > > have permissions to the event log to write with.
> > >
> > > Check the HKLM\System\CurrrentControlSet\EventLog and make sure
> whatever
> > > user your process (if WinForms the logged on user or if ASP the
> > > website/webservices' AppPool user) has write permissions to it.
> > >
> > > My appender looks like the following (although the appender
> config is from
> > a
> > > slightly older version of log4net):
> > >
> > > <appender name="EventLogAppender"
> > type="log4net.Appender.EventLogAppender">
> > >
> > >
> > > <param name="LogName" value="Application"/>
> > >
> > > <param name="ApplicationName" value="AppName"/>
> > >
> > >
> > > <layout type="log4net.Layout.PatternLayout,log4net">
> > >
> > > <param name="Header" value="[Log Header]\r\n"/>
> > >
> > > <param name="Footer" value="[Log Footer]\r\n"/>
> > >
> > > <param name="ConversionPattern" value="%c%n[%-5p] %d{ISO8601}
> .%m%n %x"/>
> > >
> > > </layout>
> > >
> > >
> > > <filter type="log4net.Filter.LevelRangeFilter">
> > >
> > > <levelMin value="ERROR" />
> > >
> > > <levelMax value="FATAL" />
> > >
> > > </filter>
> > >
> > >
> > > </appender>
> > >
> >
> >
> 


Re: Inability to use EventLogAppender with ASPNET

Posted by Matthew Brown <oc...@gmail.com>.
What event source is used by default if no ApplicationName is supplied?

On 10/12/05, Billy Barnum <b....@comcast.net> wrote:
> I agree, should be added to FAQ. There's a MS artcicle here:
> http://support.microsoft.com/default.aspx?scid=kb;en-us;329291.
>
> But you don't NEED to hack the registry. If it's a problem for you, just
> remove the LogName and ApplicationName elements from your corn-fig file and
> you should run out-of-the-box. It's been a little while, but I believe I ran
> that way at first. Of course, you won't get to have that ApplicationName
> element jam something nice that you want into the 'Source' field in the
> EventLog, but if access to the registry is a problem, ...
>
> -BillyB
>
> -----Original Message-----
> From: Matthew Brown [mailto:octavius@gmail.com]
> Sent: Wednesday, October 12, 2005 5:53 AM
> To: Log4NET User
> Subject: Re: Inability to use EventLogAppender with ASPNET
>
> Adding permission explicitly to the EventLog key (and all
> subkeys) seems to have done the trick.
>
> Maybe this should be added to the FAQ... :)
>
> On 10/11/05, Hollywood <ho...@thzero.com> wrote:
> > I've been running into this lately.  One of the items is to make sure your
> > have permissions to the event log to write with.
> >
> > Check the HKLM\System\CurrrentControlSet\EventLog and make sure whatever
> > user your process (if WinForms the logged on user or if ASP the
> > website/webservices' AppPool user) has write permissions to it.
> >
> > My appender looks like the following (although the appender config is from
> a
> > slightly older version of log4net):
> >
> > <appender name="EventLogAppender"
> type="log4net.Appender.EventLogAppender">
> >
> >
> > <param name="LogName" value="Application"/>
> >
> > <param name="ApplicationName" value="AppName"/>
> >
> >
> > <layout type="log4net.Layout.PatternLayout,log4net">
> >
> > <param name="Header" value="[Log Header]\r\n"/>
> >
> > <param name="Footer" value="[Log Footer]\r\n"/>
> >
> > <param name="ConversionPattern" value="%c%n[%-5p] %d{ISO8601} .%m%n %x"/>
> >
> > </layout>
> >
> >
> > <filter type="log4net.Filter.LevelRangeFilter">
> >
> > <levelMin value="ERROR" />
> >
> > <levelMax value="FATAL" />
> >
> > </filter>
> >
> >
> > </appender>
> >
>
>

RE: Inability to use EventLogAppender with ASPNET

Posted by Billy Barnum <b....@comcast.net>.
I agree, should be added to FAQ. There's a MS artcicle here: 
http://support.microsoft.com/default.aspx?scid=kb;en-us;329291.

But you don't NEED to hack the registry. If it's a problem for you, just
remove the LogName and ApplicationName elements from your corn-fig file and
you should run out-of-the-box. It's been a little while, but I believe I ran
that way at first. Of course, you won't get to have that ApplicationName
element jam something nice that you want into the 'Source' field in the
EventLog, but if access to the registry is a problem, ...

-BillyB

-----Original Message-----
From: Matthew Brown [mailto:octavius@gmail.com] 
Sent: Wednesday, October 12, 2005 5:53 AM
To: Log4NET User
Subject: Re: Inability to use EventLogAppender with ASPNET

Adding permission explicitly to the EventLog key (and all
subkeys) seems to have done the trick.

Maybe this should be added to the FAQ... :)

On 10/11/05, Hollywood <ho...@thzero.com> wrote:
> I've been running into this lately.  One of the items is to make sure your
> have permissions to the event log to write with.
>
> Check the HKLM\System\CurrrentControlSet\EventLog and make sure whatever
> user your process (if WinForms the logged on user or if ASP the
> website/webservices' AppPool user) has write permissions to it.
>
> My appender looks like the following (although the appender config is from
a
> slightly older version of log4net):
>
> <appender name="EventLogAppender"
type="log4net.Appender.EventLogAppender">
>
>
> <param name="LogName" value="Application"/>
>
> <param name="ApplicationName" value="AppName"/>
>
>
> <layout type="log4net.Layout.PatternLayout,log4net">
>
> <param name="Header" value="[Log Header]\r\n"/>
>
> <param name="Footer" value="[Log Footer]\r\n"/>
>
> <param name="ConversionPattern" value="%c%n[%-5p] %d{ISO8601} .%m%n %x"/>
>
> </layout>
>
>
> <filter type="log4net.Filter.LevelRangeFilter">
>
> <levelMin value="ERROR" />
>
> <levelMax value="FATAL" />
>
> </filter>
>
>
> </appender>
>


Re: Inability to use EventLogAppender with ASPNET

Posted by Matthew Brown <oc...@gmail.com>.
Adding permission explicitly to the EventLog key (and all
subkeys) seems to have done the trick.

Maybe this should be added to the FAQ... :)

On 10/11/05, Hollywood <ho...@thzero.com> wrote:
> I've been running into this lately.  One of the items is to make sure your
> have permissions to the event log to write with.
>
> Check the HKLM\System\CurrrentControlSet\EventLog and make sure whatever
> user your process (if WinForms the logged on user or if ASP the
> website/webservices' AppPool user) has write permissions to it.
>
> My appender looks like the following (although the appender config is from a
> slightly older version of log4net):
>
> <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
>
>
> <param name="LogName" value="Application"/>
>
> <param name="ApplicationName" value="AppName"/>
>
>
> <layout type="log4net.Layout.PatternLayout,log4net">
>
> <param name="Header" value="[Log Header]\r\n"/>
>
> <param name="Footer" value="[Log Footer]\r\n"/>
>
> <param name="ConversionPattern" value="%c%n[%-5p] %d{ISO8601} .%m%n %x"/>
>
> </layout>
>
>
> <filter type="log4net.Filter.LevelRangeFilter">
>
> <levelMin value="ERROR" />
>
> <levelMax value="FATAL" />
>
> </filter>
>
>
> </appender>
>
>
> ----- Original Message -----
> From: "Billy Barnum" <b....@comcast.net>
> To: "'Log4NET User'" <lo...@logging.apache.org>; "'Matthew Brown'"
> <oc...@gmail.com>
> Sent: Tuesday, October 11, 2005 5:20 PM
> Subject: RE: Inability to use EventLogAppender with ASPNET
>
>
> Try removing your line:
>
> <logName value="Application"/>
>
> I think what you're doing there is naming a custom EventLog with the same
> name as the existing Application log, which in turn requires write access to
> the registry. Just remove that line and see what happens.
>
> -BillyB
>
>
>
> WILLIAM BARNUM
> b.barnum@comcast.net
>
> ________________________________________
> From: Matthew Brown [mailto:octavius@gmail.com]
> Sent: Monday, October 10, 2005 1:43 PM
> To: Log4NET User
> Subject: Inability to use EventLogAppender with ASPNET
>
> With log4net internal debugging turned on, an attempt to create an
> EventLogAppender for a web application is failing:
>
> [3616] log4net: XmlHierarchyConfigurator: Setting Property [Layout] to
> object [log4net.Layout.PatternLayout]
> [3616] log4net: XmlHierarchyConfigurator: Setting Property [LogName] to
> String value [Application]
> [3616] log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
> [EventLog] of type [log4net.Appender.EventLogAppender]. Reported error
> follows.
> [3616] System.Security.SecurityException: Requested registry access is not
> allowed.
> [3616] at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean
> writable)
> [3616] at System.Diagnostics.EventLog.FindSourceRegistration(String
> source, String machineName, Boolean readOnly)
> [3616] at System.Diagnostics.EventLog.SourceExists(String source, String
> machineName)
> [3616] at System.Diagnostics.EventLog.SourceExists(String source)
> [3616] at log4net.Appender.EventLogAppender.ActivateOptions()
> [3616] at
> log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlEleme
> nt appenderElement)
> [3616] log4net:ERROR XmlHierarchyConfigurator: Appender named [EventLog] not
> found.
> [3616] log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
> [3616] log4net: AppenderSkeleton: Finalizing appender named [EventLog].
>
> The FAQ on the log4net site says that the ASPNET account has permission to
> write to the event log if created already. Just to be sure, I made sure to
> add ASPNET and IUSR_machinename to the Administrators group, but this does
> not work either.
>
> Here is my configuration:
>
> <appender name="EventLog" type="log4net.Appender.EventLogAppender" >
> <layout type="log4net.Layout.PatternLayout">
> <conversionPattern value="%date
> [%thread][%mdc{AspNetSessionID}] %-5level %logger - %message%newline" />
> </layout>
> <logName value="Application"/>
> </appender>
>
> <root>
> <level value="ALL" />
> <appender-ref ref="LogFileAppender" />
> <appender-ref ref="EventLog" />
> </root>
>
> Sorry if this is a silly newbie question, but I couldn't find much out there
> on configuring/using EventLogAppender besides "its tough". Can anyone help?
>
> Thanks,
> Matt Brown
>
>

Re: Inability to use EventLogAppender with ASPNET

Posted by Hollywood <ho...@thzero.com>.
I've been running into this lately.  One of the items is to make sure your 
have permissions to the event log to write with.

Check the HKLM\System\CurrrentControlSet\EventLog and make sure whatever 
user your process (if WinForms the logged on user or if ASP the 
website/webservices' AppPool user) has write permissions to it.

My appender looks like the following (although the appender config is from a 
slightly older version of log4net):

<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">


<param name="LogName" value="Application"/>

<param name="ApplicationName" value="AppName"/>


<layout type="log4net.Layout.PatternLayout,log4net">

<param name="Header" value="[Log Header]\r\n"/>

<param name="Footer" value="[Log Footer]\r\n"/>

<param name="ConversionPattern" value="%c%n[%-5p] %d{ISO8601} .%m%n %x"/>

</layout>


<filter type="log4net.Filter.LevelRangeFilter">

<levelMin value="ERROR" />

<levelMax value="FATAL" />

</filter>


</appender>


----- Original Message ----- 
From: "Billy Barnum" <b....@comcast.net>
To: "'Log4NET User'" <lo...@logging.apache.org>; "'Matthew Brown'" 
<oc...@gmail.com>
Sent: Tuesday, October 11, 2005 5:20 PM
Subject: RE: Inability to use EventLogAppender with ASPNET


Try removing your line:

<logName value="Application"/>

I think what you're doing there is naming a custom EventLog with the same
name as the existing Application log, which in turn requires write access to
the registry. Just remove that line and see what happens.

-BillyB



WILLIAM BARNUM
b.barnum@comcast.net

________________________________________
From: Matthew Brown [mailto:octavius@gmail.com]
Sent: Monday, October 10, 2005 1:43 PM
To: Log4NET User
Subject: Inability to use EventLogAppender with ASPNET

With log4net internal debugging turned on, an attempt to create an
EventLogAppender for a web application is failing:

[3616] log4net: XmlHierarchyConfigurator: Setting Property [Layout] to
object [log4net.Layout.PatternLayout]
[3616] log4net: XmlHierarchyConfigurator: Setting Property [LogName] to
String value [Application]
[3616] log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[EventLog] of type [log4net.Appender.EventLogAppender]. Reported error
follows.
[3616] System.Security.SecurityException: Requested registry access is not
allowed.
[3616] at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean
writable)
[3616] at System.Diagnostics.EventLog.FindSourceRegistration(String
source, String machineName, Boolean readOnly)
[3616] at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
[3616] at System.Diagnostics.EventLog.SourceExists(String source)
[3616] at log4net.Appender.EventLogAppender.ActivateOptions()
[3616] at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlEleme
nt appenderElement)
[3616] log4net:ERROR XmlHierarchyConfigurator: Appender named [EventLog] not
found.
[3616] log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
[3616] log4net: AppenderSkeleton: Finalizing appender named [EventLog].

The FAQ on the log4net site says that the ASPNET account has permission to
write to the event log if created already. Just to be sure, I made sure to
add ASPNET and IUSR_machinename to the Administrators group, but this does
not work either.

Here is my configuration:

<appender name="EventLog" type="log4net.Appender.EventLogAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date
[%thread][%mdc{AspNetSessionID}] %-5level %logger - %message%newline" />
</layout>
<logName value="Application"/>
</appender>

<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="EventLog" />
</root>

Sorry if this is a silly newbie question, but I couldn't find much out there
on configuring/using EventLogAppender besides "its tough". Can anyone help?

Thanks,
Matt Brown


RE: Inability to use EventLogAppender with ASPNET

Posted by Billy Barnum <b....@comcast.net>.
Try removing your line:

            <logName value="Application"/>

I think what you're doing there is naming a custom EventLog with the same
name as the existing Application log, which in turn requires write access to
the registry. Just remove that line and see what happens.

-BillyB



WILLIAM BARNUM
b.barnum@comcast.net

________________________________________
From: Matthew Brown [mailto:octavius@gmail.com] 
Sent: Monday, October 10, 2005 1:43 PM
To: Log4NET User
Subject: Inability to use EventLogAppender with ASPNET

With log4net internal debugging turned on, an attempt to create an
EventLogAppender for a web application is failing:

[3616] log4net: XmlHierarchyConfigurator: Setting Property [Layout] to
object [log4net.Layout.PatternLayout] 
[3616] log4net: XmlHierarchyConfigurator: Setting Property [LogName] to
String value [Application] 
[3616] log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[EventLog] of type [log4net.Appender.EventLogAppender]. Reported error
follows. 
[3616] System.Security.SecurityException: Requested registry access is not
allowed. 
[3616]    at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean
writable) 
[3616]    at System.Diagnostics.EventLog.FindSourceRegistration(String
source, String machineName, Boolean readOnly) 
[3616]    at System.Diagnostics.EventLog.SourceExists(String source, String
machineName) 
[3616]    at System.Diagnostics.EventLog.SourceExists(String source) 
[3616]    at log4net.Appender.EventLogAppender.ActivateOptions() 
[3616]    at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlEleme
nt appenderElement) 
[3616] log4net:ERROR XmlHierarchyConfigurator: Appender named [EventLog] not
found. 
[3616] log4net: XmlHierarchyConfigurator: Hierarchy Threshold [] 
[3616] log4net: AppenderSkeleton: Finalizing appender named [EventLog]. 

The FAQ on the log4net site says that the ASPNET account has permission to
write to the event log if created already. Just to be sure, I made sure to
add ASPNET and IUSR_machinename to the Administrators group, but this does
not work either.

Here is my configuration:

<appender name="EventLog" type="log4net.Appender.EventLogAppender" >
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date
[%thread][%mdc{AspNetSessionID}] %-5level %logger - %message%newline" />
            </layout>
            <logName value="Application"/>
        </appender>

        <root>
            <level value="ALL" />
            <appender-ref ref="LogFileAppender" />
            <appender-ref ref="EventLog" />
        </root>

Sorry if this is a silly newbie question, but I couldn't find much out there
on configuring/using EventLogAppender besides "its tough". Can anyone help?

Thanks,
Matt Brown