c# - .net trace listener for each switch -


currently in application have many trace switch , boolean switch. listener configured log text file. , works. code snippet below.

<configuration> <system.diagnostics> <switches>   <add name="booleanswitch1" value="true"/>   <add name="booleanswitch2" value="true"/>   <add name="traceswitch1" value="4"/>   <add name="traceswitch2" value="1"/> </switches> <trace autoflush="true" indentsize="2">   <listeners>     <add name="tracetestinglistner" type="system.diagnostics.textwritertracelistener" initializedata="d:\traces\tracetesting.log" traceoutputoptions="datetime">     </add>   </listeners> </trace> 

i want each switch logs put different log file. how can achieve that.

can add listener each switch , redirect log different log files? if how this?

thank help.

idea taken using more 1 trace listeners

you can configure tracesource below using multiple trace source , having separate listener each source

<configuration> <system.diagnostics> <switches>   <add name="booleanswitch1" value="true"/>   <add name="booleanswitch2" value="true"/>   <add name="traceswitch1" value="4"/>   <add name="traceswitch2" value="1"/> </switches>     <sources>       <source name="booleanswitch1source" switchname="booleanswitch1" switchtype="system.diagnostics.sourceswitch">         <listeners>           <clear />     <add name="tracetestinglistner" type="system.diagnostics.textwritertracelistener" initializedata="d:\traces\tracetesting.log" traceoutputoptions="datetime">         </listeners>       </source>       <source name="booleanswitch2source" switchname="booleanswitch2" switchtype="system.diagnostics.sourceswitch">         <listeners>           <clear />     <add name="tracetestinglistner1" type="system.diagnostics.textwritertracelistener" initializedata="d:\traces\tracetesting1.log" traceoutputoptions="datetime">         </listeners>       </source>     </sources>   </system.diagnostics> </configuration> 

you can define tracesource like

tracesource bswitch1 = new tracesource("booleanswitch1source"); 

also, check below posts

defining multiple tracesources not running

how to: use tracesource , filters trace listeners


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -