How to log to different log file when using file-based configuration source?

Topics: Exception Handling Application Block, Logging Application Block
Jun 15, 2012 at 11:45 PM

I have a configuration file that I have generated that will log errors and handle exceptions for a dll project.  Other applications will reference this dll within their application and in the application's configuration file a configuration sources block will be add and a file-based configuration source will be added that will point to the configuration project of the dll.  I was able to get the logging working in this scenario.  However, if I try to add a Logging Settings block to the configuration log of the application and specify a Rolling Flat File Listeners to log the file to a different log file I noticed that all the logs are now going into the applications log file instead of logs from the application going into one log file and the logs from the dll project going into another.  Does anyone know what I am missing and if this can be done?  This is how my xml file looks:


<?xml version="1.0" encoding="utf-8" ?>
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
        <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
            <add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                fileName="C:\Users\lylh\Desktop\MCPFileAPI\ReadDiskWriteDisk\log\test.log" />
            <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
                name="Text Formatter" />
            <add switchValue="All" name="General">
                    <add name="Rolling Flat File Trace Listener" />
            <allEvents switchValue="All" name="All Events" />
            <notProcessed switchValue="All" name="Unprocessed Category" />
            <errors switchValue="All" name="Logging Errors &amp; Warnings">
                    <add name="Rolling Flat File Trace Listener" />
    <enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source"
        parentSource="Interface Configuration">
            <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="Interface Configuration" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                filePath="Interface.config" />


Jun 30, 2012 at 6:45 AM

Is this still an issue or did you solve it with the processID change?

Randy Levy
Enterprise Library support engineer 

Jul 2, 2012 at 4:03 PM

Hi Randy,

I was able to get to work by adding the process ID. I am just trying to see if I can get it to work with the configuration tool. I was able to get the listener to display within the tool, but when it generates the xml it doesn’t seem to reference the correct name space and name. It is putting in the Microsoft name space. If I modify the configuration file manually I am able to get it to work. So I am still trying to figure out what is causing that. I also have one more question. If I want to have each log file created with a certain informational heading like for instance the machine name, Application domain, etc do you know what I would I would need to change in order to get this to work? I would like to have the initial log and any rolling logs contain this initial heading information.

Thank you,


Linh Ly | Software Engineer | Cloud Engineering

Unisys | 9701 Jeronimo Road | Irvine CA, 92618 | Net2 656-5334 | 949-380-5334

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

Jul 3, 2012 at 3:37 AM

If you want seamless integration with the configuration tool you will need to create both a custom trace listener and a custom trace listener data class.  

Enterprise Library does not support per file header information; if you need that feature, then you will need to create a custom trace listener.

I would recommend looking at the Extensibility Hands on Labs and/or looking at the Rolling XML Trace Listener Sample on the Samples Page for examples with full integration.  Also remember to either deploy your trace listener to the same directory that the configuration tool is running out of so that the configuration tool can locate your custom type.

Randy Levy
Enterprise Library support engineer