How to prefix the logfile name with the server name using Enterprise logger?

Topics: Enterprise Library Core
Sep 2, 2011 at 3:59 AM

Hi,

 

We would like to find out how to prefix the logfile name with the server name. This is in the web.config for the enterprise logger to work.

 

<add fileName="Logs\Trace.log" footer="" formatter="CustomTxtFormatter" header="----------------------------------------" rollFileExistsBehavior="Increment" rollInterval="None" rollSizeKB="5120" timeStampPattern="yyyy-MM-dd" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Rolling Flat File Trace Listener"/>

      <add fileName="Logs\Exception.log" footer="" formatter="CustomTxtFormatter" header="----------------------------------------" rollFileExistsBehavior="Increment" rollInterval="None" rollSizeKB="5120" timeStampPattern="yyyy-MM-dd" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Rolling Flat File Trace Listener1"/>

      <add fileName="Logs\FulfillmentEvents.log" footer="" formatter="CustomLogFormatter" header="" rollFileExistsBehavior="Overwrite" rollInterval="None" rollSizeKB="15360" timeStampPattern="ddd-HH-mm" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Rolling Flat File Trace Listener2"/>

      <add fileName="Logs\Jobs.log" footer="" formatter="CustomTxtFormatter" header="----------------------------------------" rollFileExistsBehavior="Increment" rollInterval="None" rollSizeKB="5120" timeStampPattern="yyyy-MM-dd" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Rolling Flat File Trace Listener3"/>

 

How do I make the server write to Logs\ServerName_Trace.log?

 

This is to prepare for Application’s High Availability configuration, where all the IIS will use the same file share and prevent concurrency condition.

 

We were  thinking there ought to be a way to either:

1)      Denote server name in the web.config like this: add fileName="%MACHINE%\Trace.log" 

2)      Or programmatically, prefix the server name in code. Then we can do this in the LoggerUtility.

 

 

 

Thanks.



-Maran

Sep 2, 2011 at 5:07 AM

Hi,

The first one would be the easiest way to achieve that though I believe using %COMPUTERNAME% will work instead of %MACHINE% token. The second option would include a lot of task since you will need to create your custom trace listener and modify the part that creates the file.

 

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

 

 

Sep 2, 2011 at 8:33 PM
Thanks Noel.

Do you have sample for Custom Trace Listener?

-Maran


From: [email removed]
To: [email removed]
Date: Thu, 1 Sep 2011 21:07:34 -0700
Subject: Re: How to prefix the logfile name with the server name using Enterprise logger? [entlib:271244]

From: AvanadeSupport
Hi,
The first one would be the easiest way to achieve that though I believe using %COMPUTERNAME% will work instead of %MACHINE% token. The second option would include a lot of task since you will need to create your custom trace listener and modify the part that creates the file.

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


Read the full discussion online.
To add a post to this discussion, reply to this email (entlib@discussions.codeplex.com)
To start a new discussion for this project, email entlib@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Sep 5, 2011 at 8:52 AM

Hi,

I don't have a sample but you can refer here on how it is done. Another option would be using the Fluent Configuration API where you can define your filename at runtime.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

 

Sep 6, 2011 at 10:31 AM

Hi,

 

Do you mean that <add fileName="Logs\%COMPUTERNAME%_Trace.log" ... will work?

That the Enterprise Library can read the %COMPUTERNAME% variable correctly?

The reason we are asking is because we are looking at shared configuration in IIS7 and sharing the web.config (and EntLib configuration) across multiple nodes.

Thus, our current entLib configuration will cause multiple nodes to write to the same UNC location.

One way is to write the log files to local drive, which we are trying to avoid. Instead, we are looking for a solution to write them to the UNC path but with different directory or file names.

Do advise.

 

Thanks.

Sep 7, 2011 at 10:14 AM
Edited Sep 7, 2011 at 10:16 AM

Hi,

I just want to confirm if this in a web farm setup? And is it correct that you need to sort the log per server? Though, I haven't tried it yet with the same setup, the token should work since it represents the name of the machine where the application is currently residing.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
entlib.support@avanade.com