Search code examples
web-configenterprise-library

Microsoft Enterprise Library - Filename with Servername


Good Morning,

I'm trying to unify the server logs on a common network unit like

fileName="\\NETWORK\App\log{ServerName}.log"

But I don't find a parameter that allows log files with the server name

<add name="Rolling Flat File Trace Listener"  type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0 listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, 
        fileName="\\NETWORK\App\Log\log{ServerName}.log" formatter="Text Formatter"  rollInterval="Day" timeStampPattern="_yyyy-MM-dd" maxArchivedFiles="30" />

Thx.


Solution

  • You can use environment variables in the file name. In this case %COMPUTERNAME%:

    <add name="Rolling Flat File Trace Listener"  type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0 listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, 
            fileName="\\NETWORK\App\Log\log%COMPUTERNAME%.log" formatter="Text Formatter"  rollInterval="Day" timeStampPattern="_yyyy-MM-dd" maxArchivedFiles="30" />