vfilby
vfilby

Reputation: 10008

How to debug UrlRewriter.NET?

I have looked at their help page it seems like I can register a debug logger that outputs information to the 'standard ASP.NET debug window'. My problem is I don't know what that means, if it means the debug output window in Visual Studio (where you see build output, debug output and more) I am not seeing any UrlRewriter debug output.

The rules are working (mostly) I just want to get more debug output to fix issues.

I added the register call to the rewriter section like this:

<rewriter>
    <register logger="Intelligencia.UrlRewriter.Logging.DebugLogger, Intelligencia.UrlRewriter" />
    ....
</rewriter>

I am hosting this website locally in IIS on Vista, to debug it I attach the debugger to the w3wp process.

Other selected parts from the web.config"

<compilation debug="true">
    <assemblies>
        ...
    </assemblies>
</compilation>
<trace enabled="true"/>

Where should I see the debug output from UrlRewriter.NET? If it is in the Visual Studio debug output window, any ideas why I am not seeing it there?

Upvotes: 4

Views: 1398

Answers (3)

mathijsuitmegen
mathijsuitmegen

Reputation: 2318

For anyone who wants to log the event messages to a file as well as see them in the debug output window, here's a piece of code I created.

Please only use this in a development environment, this code is not optimized.

usage:
In your asp.net application, add a reference to this library (MyPresentationLayer.Web).
Add the following element to 'rewriter' node:
<register logger="IntelligenciaExt.Web.Logging.UrlRewriterIntelligencia.FileLogger, IntelligenciaExt.Web"/>
By default the log file can be found outside your 'www' folder, in the subfolder 'intelligenciaLog'.

using System; 
using SysDiag = System.Diagnostics; 
using System.IO;

using Intelligencia.UrlRewriter.Logging;

namespace MyPresentationLayer.Web.Logging.UrlRewriterIntelligencia
{
    /// <summary>
    /// Custom logger for Intelligencia UrlRewriter.net that logs messages
    /// to a plain text file (../intelligenciaLog/log.txt).
    /// </summary>
    public class FileLogger : IRewriteLogger
    {
     private const string _logFolderName = "../intelligenciaLog";
     private const string _logFileName = "log.txt";
     private const string _appName = "UrlRewriterIntelligencia.FileLogger";

     public FileLogger()
     {
         LogToFile(Level.Info, "Created new instance of class 'FileLogger'");
     }

     public void Debug(object message)
     {
         LogToFile(Level.Debug, (string)message);
     }

     public void Error(object message, Exception exception)
     {
         string errorMessage = String.Format("{0} ({1})", message, exception);
         LogToFile(Level.Error, errorMessage);
     }

     public void Error(object message)
     {
         LogToFile(Level.Error, (string)message);
     }

     public void Fatal(object message, Exception exception)
     {
         string fatalMessage = String.Format("{0} ({1})", message, exception);
         LogToFile(Level.Fatal, fatalMessage);
     }

     public void Info(object message)
     {
         LogToFile(Level.Info, (string)message);
     }

     public void Warn(object message)
     {
         LogToFile(Level.Warn, (string)message);
     }

     private static void LogToFile(Level level, string message)
     {
         string outputMessage = String.Format("[{0} {1} {2}] {3}", DateTime.Now.ToString("yyyyMMdd HH:mm:ss"),
               _appName.PadRight(50, ' '), level.ToString().PadRight(5, ' '),
               message);
         SysDiag.Debug.WriteLine(outputMessage);
         try
         {
             string pathToLogFolder =Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _logFolderName);
             if (!Directory.Exists(pathToLogFolder))
             {
                 Directory.CreateDirectory(pathToLogFolder);
             }

             string fullPathToLogFile = Path.Combine(pathToLogFolder, _logFileName);
             using (StreamWriter w = File.AppendText(fullPathToLogFile))
             {
                 w.WriteLine(outputMessage);
                 // Update the underlying file.
                 w.Flush(); // Close the writer and underlying file.
                 w.Close();
             }
         }
         catch (Exception) { }
     }

     internal enum Level
     {
         Warn,
         Fatal,
         Info,
         Error,
         Debug
     }
    } 
}

Upvotes: 0

mathijsuitmegen
mathijsuitmegen

Reputation: 2318

I wanted to debug because I had the impression my rewrite rules weren't functioning.

After a while I figured out I had to alter my web.config and add the following line to the 'system.web', 'httpModules' section:

 <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>

Upvotes: 0

Aristos
Aristos

Reputation: 66641

Try to run the DebugView for read the messages from Intelligencia.UrlRewriter

Get it from here http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx

I see the source code, and I belive thats works, but if not works, then why not get the source code, and compile it with your project and just debug it on site ?

Upvotes: 1

Related Questions