Usage of the TraceSource object in asp.net

  • Thread starter Daniel Knöpfel
  • Start date
D

Daniel Knöpfel

Hi

We have to decided to use standard .net components for logging our asp.net
application (rather than log4.net or microsoft logging application blocks):
i tried to implement our logging using the TraceSource class. However, it
does not log anything. It works in a windows application but not in asp.net.

Am i doing something wrong or does the TraceSource class not work with
asp.net 2.0 ? This seems rather strange to me. At the bottom you find code
snippets from my web.config and my logging function:

Thanks for any help.

By the way, i do not seem to be the only one having this problem:
http://www.thescripts.com/forum/thread683962.html (Unfortunately, the guy
didnt get an answer)


<system.diagnostics>

<sources>

<source name ="Test">

<listeners>

<add name ="DelimitedListTraceListener" />

</listeners>

</source>

<source name ="Default">

<listeners>

<add name ="XmlWriterTraceListener" />

</listeners>

</source>

</sources>

<sharedListeners>

<add name="DelimitedListTraceListener"
type="System.Diagnostics.DelimitedListTraceListener" delimiter=":"

initializeData="delimitedOutput.txt"

traceOutputOptions="ProcessId, DateTime" />

<add name="XmlWriterTraceListener"
type="System.Diagnostics.XmlWriterTraceListener"

initializeData="xmlOutput.xml"

traceOutputOptions="ProcessId, DateTime"

/>



</sharedListeners>

<switches>

<add name="Test" value="Verbose"/>

<add name="default" value="Verbose"/>

</switches>

</system.diagnostics>





Logging function:



public void Log(Exception pException, string pOriginStringOrKey,
TraceEventType pTraceEventType, bool pAddEnvironmentInformation)

{

try

{

if (pAddEnvironmentInformation)

{

IEnvironmentProvider provider =
EnvironmentProviderFactory.GetEnvironmentProvider();

provider.AddEnvInformationToException(pException);

}

string messageString = GetMessageStringFromException(pException);

// log to specific tracesource

try

{

TraceSource traceSource = new TraceSource(pOriginStringOrKey);

traceSource.TraceEvent(pTraceEventType, 0, messageString);

traceSource.Flush();

}

catch

{

}

// log to default trace source

try

{

TraceSource defaultTraceSource = new TraceSource(DEFAULTRACESOURCE);

defaultTraceSource.TraceEvent(pTraceEventType, 0, messageString);

defaultTraceSource.Flush();

}

catch

{

}

}

catch

{

// ignore exceptions in log

}

}







I am trying to use the TraceSource object
 
D

Daniel Knöpfel

I managed that the files get created but nothing was ever written to the
files. (The files in the asp root directory and read/write access to
everyone is given). I cannot imagine that i am the only one having this
problem. Maybe its something simple that i have been overlooking all the
time. Please help

This is the important part from the web.config:
<system.diagnostics>

<trace autoflush="true">

<listeners>



<add name="Testudu"

type="System.Diagnostics.TextWriterTraceListener, System,
Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

initializeData="C:\Documents and Settings\d.kn\My Documents\Visual Studio
2005\WebSites\WebSite1\Asptsttrace.log" />


</listeners>

</trace>


<sources >

<source name="Test" switchName="TestSwitch" >

<listeners >

<add name="DelimitedListTraceListener" />




</listeners>

</source>



</sources>

<sharedListeners >

<add name="DelimitedListTraceListener"
type="System.Diagnostics.DelimitedListTraceListener" delimiter=":"

initializeData="D:\Projects\Gisab\prototypes\WebSite1\AspDumitLLogg.log" />

<add name="XmlWriterTraceListener"
type="System.Diagnostics.XmlWriterTraceListener"

initializeData="xxmlOutputTest.xml"

/>

</sharedListeners>

<switches >

<add name="TestSwitch" value="1"/>

</switches>


</system.diagnostics>







Here my code snippets to do the logging:

_traceSource.TraceInformation("testing jaaaaabbbbbbbbbuhuu");

_traceSource.Flush();

_traceSource.TraceEvent(TraceEventType.Error, 0, "erorrrror");

_traceSource.Flush();

_traceSource.TraceEvent(TraceEventType.Critical, 0, "erorrrror critical");

_traceSource.Flush();

_traceSource.TraceEvent(TraceEventType.Verbose, 0, "erorrrror verboose");

_traceSource.Flush();

_traceSource.TraceEvent(TraceEventType.Warning, 0, "erorrrror warning");

_traceSource.Flush();



_traceSource.TraceEvent(TraceEventType.Information, 0, "erorrrror info");

_traceSource.Flush();
 
D

Daniel Knöpfel

Hi

It still does not work, so we resorted to use Log4Net, which works very
well.

Greetings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top