Pierre Greborio.NET

Talking about .NET world

Tracing in ASP.NET

I continued my tests without much success. I rolledback to FX1.1 and create a basic web service:

<%@ WebService Language=C# Class=Util %>
 
 using System;
 using System.Web.Services;

 [WebService(Namespace="urn:pierre")]
 public class Util : WebService {

   [WebMethod()]
   public string Time() {
      System.Diagnostics.Trace.WriteLine("Time call");
      return Context.Timestamp.TimeOfDay.ToString();
   }
 }

Then I created its web.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <system.diagnostics>
  <trace autoflush="false" indentsize="2">
   <listeners>
    <add name="traceListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="D:\Inetpub\wwwroot\log\myTest.log" />
   </listeners>
  </trace>
 </system.diagnostics>
</configuration>

Finally I created myTest.log file (empty) getting the modify rights to ASPNET user on the folder D:\Inetpub\wwwroot\log

Running the web service nothing happens. The log file is still empty. I've searched on Google but it seems that many people requested help but there isn't a solution available (or I didn't find it). Any clues ?

Comments

TrackBack said:

# December 30, 2004 4:44 AM

Matt Hawley said:

I believe trace listeners will only write the data to the file once you've 1) closed the trace listener manually, or 2) the process writing to the trace listener ends.

Now, you could probably roll your own listener to do nearly the same thing, but its quite possible that you'll get a high-load of disk access by opening / closing the files one after another. Another problem is that if you get multiple users writing to the trace, you're going to get disk access errors with the log file.
# December 30, 2004 10:05 AM

Pierre Greborio said:

Matt,
I know this is just a basic test. The TextWriterTraceListener isn't applicable on a production system and it is required another type of listener who supports better the concurrency (ie. sql table, msmq, smtp, ...).

In any case, I found the solution and I'll post it soon.
# December 30, 2004 10:29 AM

mac said:

set autoflush="true"

# August 8, 2007 11:13 PM