Rolling FlatFile Trace Listener not adding TimeStamp to filename

Topics: Enterprise Library Core, Logging Application Block
May 22, 2008 at 1:19 AM
I'm using the Logging Application Block to create a Rolling FlatFile Trace Listener to create a log file that will contain a day's worth of log data.  A new log file should be created each day, with the date appended to the filename.  I have it configured this way:

<

configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0" />
</configSections>
<
loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<
add fileName="Logs\Report.log" formatter="Progress Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0" name="Rolling FlatFile TraceListener" rollInterval="Day" rollFileExistsBehavior="Increment" timeStampPattern="yyyy-MM-dd" />
</listeners>
<
formatters>
<
add template="{timestamp} Category: {category} Message: {message}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0" name="Progress Formatter" />
</formatters>
<
categorySources>
<
add switchValue="Information" name="Status">
<
listeners>
<
add name="Rolling FlatFile TraceListener" />
</
listeners>
</
add>
</categorySources>

This works to the extent that the application will create a log file -- named Report.log -- but it does not append the date timestamp to the filename.  Even waiting for next day, the filename stays Report.log, and data is appended to it.

How can I get this to work for me?

Bill Bowlus

 

May 23, 2008 at 12:21 AM
Here's an update.  (Note:  All times are Central Daylight Time).

When I ran my app the day before yesterday, it created a log file named Report.log (5/20/08 at 7:04pm), and continued to add to it throughout that day and the next (5/21/08).  The last entry in it has a timestamp of 05/12/08 7:03pm.  Then yesterday, at 7:05pm, it renamed (or copied?) that file to Report.2008-05-21.1.log and started a new Report.log (which is still being added to).

(Why the .1 increment was added is curious since there was no Report.2008-05-21.log file already in existence when the rollover took place.  But I can live with that...)

It appears the date is being appended to the original log file's name and a new log file created at the time the first new entry is attempted that is more than 24 hours after the creation of the original log file.  If that's the case, then the current file (Report.log) will be added to up until 7:05pm today, and then when the next entry is attempted (say at 7:08pm) it will be renamed (to Report.2008-05-22.1.log) and a new Report.log created to hold the 7:08pm entry.

So it appears using the Rollover FlatFile Trace Listener only means your log file is guaranteed to get no more than 1 day's worth of log entries, even though the start and end times of that 24 hour period are different for each log file.

If this is the case, it means the times of the first entries in the logs will start to slip forward over time.  If I were to start the program running at midnight and the first entry to the first log was created a few minutes later, then the first log would have a creation time of 12:03am.  The file would collect entries throughout the day -- and possibly include an entry added at 12:02am the following day.  This would worsen as the days progressed.  (In what logging scenarios would this type of behavior be useful?)

That isn't what I need.  I need the log file to start with the current date appended to the name, and when the first entry is made for the following day a new log file is created with that day's date appended.  It should then collect entries for that day up to the change of date, at which time a new log file is created with a filename appended with that day's date.

Is there a way to coax the Rolling FlatFile Trace Listener to behave that way?

Bill Bowlus
May 6, 2010 at 11:15 AM

but i want every day has one directory? what should i do ?

 

 

May 6, 2010 at 11:17 AM

when i use "XML Trace Listener" , the xml result is ,there is more than one root element in xml files? is it error? what should i do , i want xml file is right?

 

thank you very much !!

 

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
  <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
    <EventID>100</EventID>
    <Type>3</Type>
    <SubType Name="Information">0</SubType>
    <Level>8</Level>
    <TimeCreated SystemTime="2010-05-06T10:14:15.7656250Z" />
    <Source Name="Trace" />
    <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
    <Execution ProcessName="WebDev.WebServer" ProcessID="9752" ThreadID="10" />
    <Channel/>
    <Computer>SHIWB</Computer>
  </System>
  <ApplicationData>
    <TraceData>
      <DataItem>
        <LogEntry>
          <Message>information message</Message>
          <Categories>
            <String>Trace</String>
          </Categories>
          <Priority>3</Priority>
          <EventId>100</EventId>
          <Severity>Information</Severity>
          <LoggedSeverity>Information</LoggedSeverity>
          <Title />
          <TimeStamp>2010-5-6 10:14:15</TimeStamp>
          <MachineName>SHIWB</MachineName>
          <AppDomainName>89d819cc-8-129176144528437500</AppDomainName>
          <ProcessId>9752</ProcessId>
          <ProcessName>C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe</ProcessName>
          <ManagedThreadName />
          <Win32ThreadId>9860</Win32ThreadId>
          <ExtendedProperties>
            <KeyValuePair_2>
              <Key>1</Key>
              <Value>&lt;log&gt;&lt;id&gt;1&lt;/id&gt;&lt;name&gt;shiwenbin&lt;/name&gt;&lt;/log&gt;</Value>
            </KeyValuePair_2>
            <KeyValuePair_2>
              <Key>2</Key>
              <Value>2</Value>
            </KeyValuePair_2>
          </ExtendedProperties>
          <TimeStampString>2010-5-6 10:14:15</TimeStampString>
          <ActivityId>00000000-0000-0000-0000-000000000000</ActivityId>
          <RelatedActivityId />
          <ErrorMessages />
          <ActivityIdString>00000000-0000-0000-0000-000000000000</ActivityIdString>
          <CategoriesStrings>
            <String>Trace</String>
          </CategoriesStrings>
        </LogEntry>
      </DataItem>
    </TraceData>
  </ApplicationData>
</E2ETraceEvent>
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
  <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
    <EventID>100</EventID>
    <Type>3</Type>
    <SubType Name="Information">0</SubType>
    <Level>8</Level>
    <TimeCreated SystemTime="2010-05-06T10:14:16.9531250Z" />
    <Source Name="Trace" />
    <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
    <Execution ProcessName="WebDev.WebServer" ProcessID="9752" ThreadID="10" />
    <Channel/>
    <Computer>SHIWB</Computer>
  </System>
  <ApplicationData>
    <TraceData>
      <DataItem>
        <LogEntry>
          <Message>information message</Message>
          <Categories>
            <String>Trace</String>
          </Categories>
          <Priority>3</Priority>
          <EventId>100</EventId>
          <Severity>Information</Severity>
          <LoggedSeverity>Information</LoggedSeverity>
          <Title />
          <TimeStamp>2010-5-6 10:14:16</TimeStamp>
          <MachineName>SHIWB</MachineName>
          <AppDomainName>89d819cc-8-129176144528437500</AppDomainName>
          <ProcessId>9752</ProcessId>
          <ProcessName>C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe</ProcessName>
          <ManagedThreadName />
          <Win32ThreadId>9860</Win32ThreadId>
          <ExtendedProperties>
            <KeyValuePair_2>
              <Key>1</Key>
              <Value>&lt;log&gt;&lt;id&gt;1&lt;/id&gt;&lt;name&gt;shiwenbin&lt;/name&gt;&lt;/log&gt;</Value>
            </KeyValuePair_2>
            <KeyValuePair_2>
              <Key>2</Key>
              <Value>2</Value>
            </KeyValuePair_2>
          </ExtendedProperties>
          <TimeStampString>2010-5-6 10:14:16</TimeStampString>
          <ActivityId>00000000-0000-0000-0000-000000000000</ActivityId>
          <RelatedActivityId />
          <ErrorMessages />
          <ActivityIdString>00000000-0000-0000-0000-000000000000</ActivityIdString>
          <CategoriesStrings>
            <String>Trace</String>
          </CategoriesStrings>
        </LogEntry>
      </DataItem>
    </TraceData>
  </ApplicationData>
</E2ETraceEvent>
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
  <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
    <EventID>100</EventID>
    <Type>3</Type>
    <SubType Name="Information">0</SubType>
    <Level>8</Level>
    <TimeCreated SystemTime="2010-05-06T10:14:17.2343750Z" />
    <Source Name="Trace" />
    <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
    <Execution ProcessName="WebDev.WebServer" ProcessID="9752" ThreadID="11" />
    <Channel/>
    <Computer>SHIWB</Computer>
  </System>
  <ApplicationData>
    <TraceData>
      <DataItem>
        <LogEntry>
          <Message>information message</Message>
          <Categories>
            <String>Trace</String>
          </Categories>
          <Priority>3</Priority>
          <EventId>100</EventId>
          <Severity>Information</Severity>
          <LoggedSeverity>Information</LoggedSeverity>
          <Title />
          <TimeStamp>2010-5-6 10:14:17</TimeStamp>
          <MachineName>SHIWB</MachineName>
          <AppDomainName>89d819cc-8-129176144528437500</AppDomainName>
          <ProcessId>9752</ProcessId>
          <ProcessName>C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe</ProcessName>
          <ManagedThreadName />
          <Win32ThreadId>6388</Win32ThreadId>
          <ExtendedProperties>
            <KeyValuePair_2>
              <Key>1</Key>
              <Value>&lt;log&gt;&lt;id&gt;1&lt;/id&gt;&lt;name&gt;shiwenbin&lt;/name&gt;&lt;/log&gt;</Value>
            </KeyValuePair_2>
            <KeyValuePair_2>
              <Key>2</Key>
              <Value>2</Value>
            </KeyValuePair_2>
          </ExtendedProperties>
          <TimeStampString>2010-5-6 10:14:17</TimeStampString>
          <ActivityId>00000000-0000-0000-0000-000000000000</ActivityId>
          <RelatedActivityId />
          <ErrorMessages />
          <ActivityIdString>00000000-0000-0000-0000-000000000000</ActivityIdString>
          <CategoriesStrings>
            <String>Trace</String>
          </CategoriesStrings>
        </LogEntry>
      </DataItem>
    </TraceData>
  </ApplicationData>
</E2ETraceEvent>
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
  <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
    <EventID>100</EventID>
    <Type>3</Type>
    <SubType Name="Information">0</SubType>
    <Level>8</Level>
    <TimeCreated SystemTime="2010-05-06T10:14:17.5156250Z" />
    <Source Name="Trace" />
    <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
    <Execution ProcessName="WebDev.WebServer" ProcessID="9752" ThreadID="4" />
    <Channel/>
    <Computer>SHIWB</Computer>
  </System>
  <ApplicationData>
    <TraceData>
      <DataItem>
        <LogEntry>
          <Message>information message</Message>
          <Categories>
            <String>Trace</String>
          </Categories>
          <Priority>3</Priority>
          <EventId>100</EventId>
          <Severity>Information</Severity>
          <LoggedSeverity>Information</LoggedSeverity>
          <Title />
          <TimeStamp>2010-5-6 10:14:17</TimeStamp>
          <MachineName>SHIWB</MachineName>
          <AppDomainName>89d819cc-8-129176144528437500</AppDomainName>
          <ProcessId>9752</ProcessId>
          <ProcessName>C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe</ProcessName>
          <ManagedThreadName />
          <Win32ThreadId>7760</Win32ThreadId>
          <ExtendedProperties>
            <KeyValuePair_2>
              <Key>1</Key>
              <Value>&lt;log&gt;&lt;id&gt;1&lt;/id&gt;&lt;name&gt;shiwenbin&lt;/name&gt;&lt;/log&gt;</Value>
            </KeyValuePair_2>
            <KeyValuePair_2>
              <Key>2</Key>
              <Value>2</Value>
            </KeyValuePair_2>
          </ExtendedProperties>
          <TimeStampString>2010-5-6 10:14:17</TimeStampString>
          <ActivityId>00000000-0000-0000-0000-000000000000</ActivityId>
          <RelatedActivityId />
          <ErrorMessages />
          <ActivityIdString>00000000-0000-0000-0000-000000000000</ActivityIdString>
          <CategoriesStrings>
            <String>Trace</String>
          </CategoriesStrings>
        </LogEntry>
      </DataItem>
    </TraceData>
  </ApplicationData>
</E2ETraceEvent>
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
  <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
    <EventID>100</EventID>
    <Type>3</Type>
    <SubType Name="Information">0</SubType>
    <Level>8</Level>
    <TimeCreated SystemTime="2010-05-06T10:14:17.7812500Z" />
    <Source Name="Trace" />
    <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
    <Execution ProcessName="WebDev.WebServer" ProcessID="9752" ThreadID="4" />
    <Channel/>
    <Computer>SHIWB</Computer>
  </System>
  <ApplicationData>
    <TraceData>
      <DataItem>
        <LogEntry>
          <Message>information message</Message>
          <Categories>
            <String>Trace</String>
          </Categories>
          <Priority>3</Priority>
          <EventId>100</EventId>
          <Severity>Information</Severity>
          <LoggedSeverity>Information</LoggedSeverity>
          <Title />
          <TimeStamp>2010-5-6 10:14:17</TimeStamp>
          <MachineName>SHIWB</MachineName>
          <AppDomainName>89d819cc-8-129176144528437500</AppDomainName>
          <ProcessId>9752</ProcessId>
          <ProcessName>C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe</ProcessName>
          <ManagedThreadName />
          <Win32ThreadId>7760</Win32ThreadId>
          <ExtendedProperties>
            <KeyValuePair_2>
              <Key>1</Key>
              <Value>&lt;log&gt;&lt;id&gt;1&lt;/id&gt;&lt;name&gt;shiwenbin&lt;/name&gt;&lt;/log&gt;</Value>
            </KeyValuePair_2>
            <KeyValuePair_2>
              <Key>2</Key>
              <Value>2</Value>
            </KeyValuePair_2>
          </ExtendedProperties>
          <TimeStampString>2010-5-6 10:14:17</TimeStampString>
          <ActivityId>00000000-0000-0000-0000-000000000000</ActivityId>
          <RelatedActivityId />
          <ErrorMessages />
          <ActivityIdString>00000000-0000-0000-0000-000000000000</ActivityIdString>
          <CategoriesStrings>
            <String>Trace</String>
          </CategoriesStrings>
        </LogEntry>
      </DataItem>
    </TraceData>
  </ApplicationData>
</E2ETraceEvent>
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
  <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
    <EventID>100</EventID>
    <Type>3</Type>
    <SubType Name="Information">0</SubType>
    <Level>8</Level>
    <TimeCreated SystemTime="2010-05-06T10:14:18.0468750Z" />
    <Source Name="Trace" />
    <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
    <Execution ProcessName="WebDev.WebServer" ProcessID="9752" ThreadID="4" />
    <Channel/>
    <Computer>SHIWB</Computer>
  </System>
  <ApplicationData>
    <TraceData>
      <DataItem>
        <LogEntry>
          <Message>information message</Message>
          <Categories>
            <String>Trace</String>
          </Categories>
          <Priority>3</Priority>
          <EventId>100</EventId>
          <Severity>Information</Severity>
          <LoggedSeverity>Information</LoggedSeverity>
          <Title />
          <TimeStamp>2010-5-6 10:14:18</TimeStamp>
          <MachineName>SHIWB</MachineName>
          <AppDomainName>89d819cc-8-129176144528437500</AppDomainName>
          <ProcessId>9752</ProcessId>
          <ProcessName>C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe</ProcessName>
          <ManagedThreadName />
          <Win32ThreadId>7760</Win32ThreadId>
          <ExtendedProperties>
            <KeyValuePair_2>
              <Key>1</Key>
              <Value>&lt;log&gt;&lt;id&gt;1&lt;/id&gt;&lt;name&gt;shiwenbin&lt;/name&gt;&lt;/log&gt;</Value>
            </KeyValuePair_2>
            <KeyValuePair_2>
              <Key>2</Key>
              <Value>2</Value>
            </KeyValuePair_2>
          </ExtendedProperties>
          <TimeStampString>2010-5-6 10:14:18</TimeStampString>
          <ActivityId>00000000-0000-0000-0000-000000000000</ActivityId>
          <RelatedActivityId />
          <ErrorMessages />
          <ActivityIdString>00000000-0000-0000-0000-000000000000</ActivityIdString>
          <CategoriesStrings>
            <String>Trace</String>
          </CategoriesStrings>
        </LogEntry>
      </DataItem>
    </TraceData>
  </ApplicationData>
</E2ETraceEvent>

May 6, 2010 at 11:34 AM

<add fileName="%WINDIR%\Report.log" formatter="Progress Formatter" />

in the "C:\WINDOWS" will have one file ,named "Report.log". but when i use

<add fileName="%DATE%\Report.log" formatter="Progress Formatter" />

the file is not created.why?

 

what should i do ?

 

May 7, 2010 at 9:33 AM

Have you verified that the %DATE% environment variable is supported on your OS? If it's supported, your app may not have the permission to create the corresponding folder.  Did you check if there was any error log indicating why logging failed?  You can check this to the destination log of the trace listener you configured under the Logging Errors and Warnings section.

 

Sarah B. Urmeneta   
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 8, 2010 at 8:25 AM

do not the windows 2003 server  support %DATE%?

Jun 8, 2010 at 9:47 AM

I don't have any machine with windows server 2003 available here right now so I cannot check it from my end.

Try checking it from yours by opening up a command prompt and from there type this "echo %DATE%", this will return the value of the %DATE% environment variable.

Also, as far as I know the %DATE% environment variable is not a directory variable therefore this will not work < add  fileName="%DATE%\Report.log"  formatter="Progress Formatter" />. 

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Jun 9, 2010 at 12:03 PM

I have the same problem my rolling flat file name was not formed correctly,it's filename got appended with some guid value .Why?

Jun 10, 2010 at 6:38 AM

jayanthi,

Can you send us your logging configuration so we can take a look at it. Thanks. 

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com