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
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