RollingFlatFileListener doesn't roll the file with date

Topics: Logging Application Block
Oct 6, 2010 at 1:45 PM

Hi,
   I am using EntLib 4.0 and although I was able to use the EntLibConfig.exe from the EntLib4Src that I downloaded, the flat file doesn't put in the date in the filename. Previously when I was using an older version (I think 1 or 3), I used to put in the filename as LogFile_{Date}.txt and rolling period of 1day, it would create the file with date in it so I would have LogFile_20101005.txt for yesterday and for today LogFile_20101006.txt etc., I tried with adding as a Custom Trace Listener and overwriting by day and as well as Rolling Flat File Listener, same result. So can you please help in this regard.

Thanks,
LotusShiv

Oct 7, 2010 at 2:44 AM
Edited Oct 7, 2010 at 2:47 AM

So these are the files you're expecting:

LogFile_20101005.txt and LogFile_20101006.txt

But these are what you're getting (?)

LogFile_20101005.txt and LogFile.txt

Am I right?  This is the behavior also in version 5.0.  If you want to modify it, creating a custom trace listener is the way to go.  I'll try to setup first a machine for EntLib 4.0 and see its source code so we would know what exactly you need to modify.

 

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

Oct 26, 2010 at 5:52 AM
pshankar wrote:

Hi,
   I am using EntLib 4.0 and although I was able to use the EntLibConfig.exe from the EntLib4Src that I downloaded, the flat file doesn't put in the date in the filename. Previously when I was using an older version (I think 1 or 3), I used to put in the filename as LogFile_{Date}.txt and rolling period of 1day, it would create the file with date in it so I would have LogFile_20101005.txt for yesterday and for today LogFile_20101006.txt etc., I tried with adding as a Custom Trace Listener and overwriting by day and as well as Rolling Flat File Listener, same result. So can you please help in this regard.

Thanks,
LotusShiv

 Hello, Do you find the solution? If you find it ,can you let me know it?

Oct 26, 2010 at 7:18 AM

kefanchelin,

Can you confirm the answer to my question above?  Is it the behavior you're getting?

 

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

Oct 26, 2010 at 7:21 AM
Edited Oct 26, 2010 at 7:56 AM
AvanadeSupport wrote:

kefanchelin,

Can you confirm the answer to my question above?  Is it the behavior you're getting?

 

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

 Yes , I confirm, that's what I want to get. Can you show me the solution? I am new for the Entlib,  I need the function, but now I have no time to check the custom trace listener. I need your help, Thank you.

Oct 28, 2010 at 11:50 AM
AvanadeSupport wrote:

So these are the files you're expecting:

LogFile_20101005.txt and LogFile_20101006.txt

But these are what you're getting (?)

LogFile_20101005.txt and LogFile.txt

Am I right?  This is the behavior also in version 5.0.  If you want to modify it, creating a custom trace listener is the way to go.  I'll try to setup first a machine for EntLib 4.0 and see its source code so we would know what exactly you need to modify.

 

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

 Hello, Can you send me an example for the custom trace listener? I really need that. Thank you.

Oct 29, 2010 at 12:20 AM

I haven't really created the custom trace listener.  However, I was thinking on how to do that and haven't found a way to implement that behavior since the base class ultimately accepts only the file name during the instatiation by passing it in the constructor.  Do you know what version of EntLib which does that?  I already tried it with version 3.0 and 3.1 as mentioned by  pshankar but I'm not getting that behavior.

 

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

Oct 29, 2010 at 12:25 AM

Thank you for your replying.

 My version is 5.0. If you can find the solution. please let me know. Thank you!!

Oct 29, 2010 at 12:47 AM

Do you really need the current log file to log to the filename with the current date?  Or is it acceptable if the previous file will be roll over to a filename appended with the date yesterday?  For example, if your file roll overs today (10/29), the content of the fill will be moved to LogFile_2010-10-28.txt and the new log file will still be in LogFile.txt.  Let me know because I think this can be easier to implement.

 

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

Oct 29, 2010 at 1:05 AM

My exact requirment is to  need the  file to log to the filename with the current date, but I think that's too difficult to custom it. So if this is impossible, the second condition is also ok.

If you have the solution for the second condition , please also let me know.

Thank you.

Oct 29, 2010 at 1:15 AM

I'm currently trying it out.  Send me an email so I could send the sample custom trace listener to you once done.

 

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

Oct 29, 2010 at 1:21 AM
Edited Oct 29, 2010 at 1:23 AM

Thank you very much, my email is chenlin198412@126.com or linchen.hitsoft@gmail.com

Oct 29, 2010 at 3:11 AM

I sent it already.  Let me know if you have any questions.

 

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

Oct 29, 2010 at 3:43 AM

Thank you very much. I have received it . I will check it.

Oct 29, 2010 at 8:16 PM

Sorry for the delayed reply to kefanchenlin.  I did find a solution - these are the following steps that I followed

a) I used the previous version of RollingFlatFileListener.cs (May 2007 Enterprise library download) where in I replace the key word
  (in my case I used Date i.e. in the file name as the key and the value of the key being
   $mypath/LogFile_{Date}.txt ) to create my own Custom built ExceptionLogHandling class library
   with a few other bells and whistles.  Ofcourse I do have file name checks, path check and all that.  

b) And in the Ent4Lib config builder, i.e. EntLibConfig.exe, I opened my application web.config and
   proceeded to add a Custom Trace Listener - for which I set the settings as follows:

    Name = Custom Trace Listener
    Attributes = {Collection}   - this is where I added
                         key=fileName
                       value=$mypath/LogFile_{Date}.txt
    Filter = All
    Formatter = Text Formatter
    TraceOutputOptions = DateTime
    Type = Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener,ExceptionLogHandling

  

  and the Text Formatter - I added only the attributes that I need in the dropdownlist available

Note: Here the ExceptionLogHandling that you see in the Type setting is my custom library name.
      Also, $mypath for the file path in my case was D:/RptLogs 

And I did use all the other library files like the Common, ObjectBuilder2, Unity and Data from the Ent4Lib 
October 2008 download. Voila - I am back to business with my rolling log file by day.

 

Oct 29, 2010 at 8:18 PM
AvanadeSupport wrote:

I sent it already.  Let me know if you have any questions.

 

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

 

To Sarah,

  Are you able to achieve the rolling log file with the current version of Enterprise Library? Or rather can you share or just send me the solution that you provided to kefanchenlin?

 I would appreciate it very much.

Jul 20, 2011 at 9:59 AM

My rolling log does not rol... using enterprise lib 5, some one can help? I'd like a file with date in it's name, like log_2011-07-20.log and after a day a new log with -21 and so on.

Jul 20, 2011 at 10:53 AM

Hi,

This behavior doesn't come out of the box. You need to create a custom trace listener to achieve this, where it appends the current date to the filename. Kindly refer to this thread for more details. Hope this helps.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us