Configurable log file path in Enterprise Library 2.0

Topics: Building and extending application blocks, Logging Application Block
Sep 14, 2011 at 5:36 AM

Dear Friends,

I am using MS Ent. Lib. 2.0 in my C#.NET windows based application. I am using "Logging Application Block" and able to write "errorTrace.log" and "Trace.log" files successfully in  the Application Directory location (Installed Directory).

But due to specific business needs, I want to change the path of log file , programattically. I want to make this path user configurable so that Log file (trace.log, errortrace.log) can be written to new location.

I have tried following links but didn't solve the problem.:

http://forums.asp.net/p/994264/1963232.aspx

http://social.msdn.microsoft.com/Forums/ar/netfxbcl/thread/4d8db5d8-069c-4bdf-8ccc-a3153f89f2fc

Any help is appreciated.

 

Thanks & Regards,

G. Singh

Sep 14, 2011 at 5:53 AM

Hi,

Curious...what trace listener are you using?

Sep 14, 2011 at 6:00 AM

Hi,

I'm not sure how can this be done in Ent Lib 2.0 as this version is really old and may have limited functionality. If migration to Entlib 5.0 is an option, you can however use the Fluent Configuration API. Hope this helps.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

 

 

Sep 14, 2011 at 6:35 AM
Edited Sep 14, 2011 at 6:37 AM

Hello,

Sadly , moving to Ent. Lib. 5.0 is not an option :-( as of now. But it can be an option in future.

 

We are using "FlatFileTraceListener" as in my application.

we need to make the the path , configurable for FlatFiles (Trace.log & ErrorTrace.log).

And also relying on Config files is also not an option..

The business need is to have separate log files for separate user, once user is able to configure a separate path for his/her own use.

 

Sep 14, 2011 at 7:04 AM

Can you check this thread if the solution presented there works for you? On your second concern, you can use the File Configuration Source to achieve that. Kindly refer to this blog for on how it is done.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

Sep 14, 2011 at 7:09 AM
gurtej wrote:

The business need is to have separate log files for separate user, once user is able to configure a separate path for his/her own use.

gurtej,

As of now, what I recommend is to override the TraceData method found in the FlatFileTraceListener class. This will give you flexibility to manipulate the way your logging is done by ent lib.

Hope this helps. :-)

Sep 14, 2011 at 11:09 AM

Hello CodeTrainer,

In class FormattedTextWriterTraceListener,  there is RootFileNameAndEnsureTargetFolderExists method which take care of the location of the path.

This works for me, if I edit the path for the file here.

But from where should I pass the correct path to this method?will it be advisable?

Sep 14, 2011 at 11:51 AM

Ah, I see. If that is the case then you can modify that file so that it reads from a database for the necessary path. Then, construct a logic that checks for the existence of the path and if it exists, you can log it there as per your user's choice.

Hope my suggestion helps you! :-)