Click here to Skip to main content
15,569,840 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:

XML
<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <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=2.0.0.0, 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" />
    </listeners>
  </loggingConfiguration>
Posted
Updated 26-Jun-16 22:45pm
v2
Comments
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

Hi,

You can achieve it by simply using nLog.

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

Sample config file :
HTML
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd">
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >


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

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

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