Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am generating Log file by using loggingConfiguration from config file but I need to generate the file based on Session Value.

For Example : Now file creating as SQL.tsv but my requirement is SQL_SessionValue.tsv

What I have tried:

<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
      <add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.SystemDiagnosticsTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=5a46cd40fd11d886"
        traceOutputOptions="Timestamp" filter="All" type="System.Diagnostics.DefaultTraceListener, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        name="Diagnostics Trace Listener" initializeData="" />
      <add fileName="D:\TestSolution\TEST\Log\SQL\SQL.tsv"
        footer="" formatter="Text SQL Formatter" header="" rollFileExistsBehavior="Increment"
        rollInterval="Day" rollSizeKB="1024" timeStampPattern="yyyyMMdd"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=5a46cd40fd11d886"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=5a46cd40fd11d886"
        name="SQL Trace Listener" />
Updated 26-Jun-16 21:45pm
Herman<T>.Instance 23-Jun-16 1:48am    
What about changing the setting: fileName="D:\TestSolution\TEST\Log\SQL\SQL.tsv"
Kornfeld Eliyahu Peter 23-Jun-16 1:49am    
I think there is no way to do it at runtime...
Herman<T>.Instance 23-Jun-16 1:50am    
Did you check that properly? And why is the name of the logfile so important as requirement?
Kornfeld Eliyahu Peter 23-Jun-16 1:55am    
If it is Enterprise Library (as I think it is), that yes - the only way is to write your own trace listener...
Rakesh Tripathy 23-Jun-16 2:28am    
File name should change dynamically based on Login User id.

1 solution


You can achieve it by simply using nLog.

one simple way to do is. Simply set ThreadName what ever you want.

Sample config file :
<nlog xmlns="">
      xsi:schemaLocation=" NLog.xsd"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >

  <variable name="myvar" value="myvalue" />
    <target name="logfile" xsi:type="File" xmlns:xsi="#unknown">
  layout="${longdate} ${logger} ${message}"
  fileName="${specialfolder:folder=MyDocuments}/DynamicName/${shortdate}/Event-${threadname}.log" />

    <logger name="*" minlevel="Info" writeto="logfile" />
Share this answer
Rakesh Tripathy 28-Jun-16 0:57am    

Thank you for your suggestion, but as per my requirement I can't use nLog or log4net.

In my above code I want to change the log file name dynamically. If any solution please post.
Tabish Mateen 28-Jun-16 1:12am    
You can access the attribute which stores your path by using Attribute["filename"]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900