Log is not written with Rolling Flat File Trace Listner

Topics: Logging Application Block
Sep 24, 2008 at 11:09 AM
Hi all. i have configured Enterprise Library to Write logs using Rolling Flat File TraceListner. Here is my web.config Code

<

loggingConfiguration name="Logging Application Block" tracingEnabled="true"

 

 

defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">

 

<

listeners>

 

<

add source="Enterprise Library Logging" formatter="Text Formatter"

 

 

log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

name="Formatted EventLog TraceListener" />

 

<

add fileName="Logs/rolling.log" footer="----------------------------------------"

 

 

formatter="Text Formatter" header="--------------- Error-------------------------"

 

 

rollFileExistsBehavior="Overwrite" rollInterval="Minute" rollSizeKB="0"

 

 

timeStampPattern="yyyy-MM-dd" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

name="Rolling Flat File Trace Listener" />

 

</

listeners>

 

<

formatters>

 

<

add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"

 

 

type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

name="Text Formatter" />

 

</

formatters>

 

<

categorySources>

 

<

add switchValue="All" name="General">

 

<

listeners>

 

<

add name="Formatted EventLog TraceListener" />

 

</

listeners>

 

</

add>

 

</

categorySources>

 

<

specialSources>

 

<

allEvents switchValue="All" name="All Events" />

 

<

notProcessed switchValue="All" name="Unprocessed Category" />

 

<

errors switchValue="All" name="Logging Errors &amp; Warnings">

 

<

listeners>

 

<

add name="Formatted EventLog TraceListener" />

 

</

listeners>

 

</

errors>

 

</

specialSources>

 

</

loggingConfiguration>

And here is my Code through which i m trying to  Write some Log. But i m not able to Write any log. Can any body help me 

 

catch

(Exception ex)

 

{

 

LogEntry le = new LogEntry();

 

 

 

 

 

 

 

le.Message =

"Testing our File Logging:"+ex.Message;

 

le.EventId = 1234;

le.Title =

"File Message";

 

le.Priority = 1;

 

Logger.Write(le);

 

 

 

}

Sep 24, 2008 at 12:17 PM
I'm a bit curious also .. I have a pretty similar setup, which is basically just a trace logger configured and supposed to be working (as it works in the development environment), but on IIS on one server I am not getting any logs at all, neither does email logging work, where as on another machine I'm getting both trace logs and email logs.

Is there some IIS configuration options that need to be set for the logger library to work properly?
Sep 24, 2008 at 3:30 PM
Almost certainly it is an issue of security.  The security context the logging statements are executing under will be the issue.  Is your application:
  • using Windows Authentication?
  • using Impersonation?
  • a particular application pool identity?
The directory that you are attempting to write to needs to have the correct ACL permissions.  A good way to diagnose these issues is to use FileMon for Windows v7.04 to monitor the application. Ensure you start FileMon before starting your application. You will probably see an 'Access Denied' when trying to open your log file. Generally, you need to ensure the directory you are writing logs to allows IISWPG group write access.
Sep 24, 2008 at 3:58 PM
Yes, that is what I generally figured it could be, and I tried setting the permissions a few time today without much luck. I even gave "full control" to the "Everyone" user on the file system level in Windows, but still I was not getting anything.

I'll give Filemon a try tomorrow -- didn't think it would display operations performed by IIS, but that's a good hint - Thanks.

Sep 24, 2008 at 5:27 PM
I'm curious to see if anyone figures this out as well - I have pretty much the same issue.  All works fine on my development machine (and on my coworkers), but when I deploy to our development server, I can't get the Enterprise Library to write to the Event Log or a flat file.  My first inclination was also that it was a security issue, but I have just finished giving the "Everyone" account (plus the aspnet user and IUSR) full control of the directory I am trying to write my exceptions to and it's still a no-go.

I have downloaded and used filemon to try and identify any "denied" issues, and I don't get any so I'm at a bit of a loss as to why this isn't working.  I am running in the default app pool using anonymous authentication with .NET 3.5 on IIS 6.

The enterprise libraries don't need to be installed on the server do they?  I am assuming that including the necessary dll's in my application's bin directory is sufficient for deployment to a server for them to work (and the database application block I am using does work on the development server).

Any help with this would be greatly appreciated...
Sep 24, 2008 at 6:20 PM
I always like it when I can respond to my own posts :)

After playing around with this for a while longer, and still not getting any file access errors, I decided to see about registry access errors since that is where the event log keys and security is.  I downloaded regmon and ta-da, I was getting access denied on the registry key:

HKLM\System\CurrentControlSet001\Services\EventLog

So, after trying a few different configurations on that, I found that if you give the appropriate user (in my case this was the aspnet account) permission to that registry key (it is "full control", not just read) then I was able to output events to the event log.  I don't like having to give that particular user account access to the registry, but at this point I'm a bit stuck.

I still can't figure out why it won't write out to my flat file, even though I am trying to write to a directory contained in my main application directory.  Anyone have any thoughts on that one?
Sep 25, 2008 at 8:27 AM
i have changed my Web.Config as Follow. and now i m able to write error log:

<

loggingConfiguration name="Logging Application Block" tracingEnabled="true"

 

 

defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">

 

<

listeners>

 

<

add source="Enterprise Library Logging" formatter="Text Formatter"

 

 

log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

name="Formatted EventLog TraceListener" />

 

<

add fileName="Logs/rolling.log" footer="----------------------------------------"

 

 

formatter="Text Formatter" header="---------------Bizlogix Error-------------------------"

 

 

rollFileExistsBehavior="Overwrite" rollInterval="Minute" rollSizeKB="0"

 

 

timeStampPattern="yyyy-MM-dd" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

name="Rolling Flat File Trace Listener" />

 

</

listeners>

 

<

formatters>

 

<

add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"

 

 

type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

name="Text Formatter" />

 

</

formatters>

 

<

categorySources>

 

<

add switchValue="All" name="General">

 

<

listeners>

 

<

add name="Formatted EventLog TraceListener" />

 

<

add name="Rolling Flat File Trace Listener" />

 

</

listeners>

 

</

add>

 

</

categorySources>

 

<

specialSources>

 

<

allEvents switchValue="All" name="All Events" />

 

<

notProcessed switchValue="All" name="Unprocessed Category" />

 

<

errors switchValue="All" name="Logging Errors &amp; Warnings">

 

<

listeners>

 

<

add name="Formatted EventLog TraceListener" />

 

<

add name="Rolling Flat File Trace Listener" />

 

</

listeners>

 

</

errors>

 

</

specialSources>

 

</

loggingConfiguration>

i just added Trace Listner Reference (and set its property "ReferencedTraceListner" to appropriate Rolling File Trace Listner) to "General Node" and in "Logging Error Warnings" under speciall sources

 

Oct 1, 2008 at 1:17 PM
Just getting back to looking at this error again - too many projects, not enough time :)

Anyway, the fix for me was to add the

<add name="Rolling Flat File Trace Listener" />

directive to the <listeners> section of the <errors> node of the <specialSources> node.  Thanks for the help jassimmunir....very strange that without that entry, it still works on my development machine to write out errors.