How to debug UrlRewriter.NET?

I looked at their help page, it seems to me that I can register a debug log that displays information in a standard ASP.NET debug window. My problem is that I don’t know what it means if it means the debug output window in Visual Studio (where you see assembly output, debug output, etc.), I don’t see UrlRewriter debug output.

The rules work (mostly) I just want more debugging output to fix the problems.

I added a register call to the rewrite section as follows:

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

I host this site locally in IIS on Vista to debug it. I am attaching a debugger to the w3wp process.

Other selected parts from web.config "

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

Where can I see UrlRewriter.NET debug output? If it is in the Visual Studio debug output window, any ideas why I can't see it?

+4
source share
3 answers

Try running DebugView to read messages from Intelligencia.UrlRewriter

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

I see the source code, and I believe that it works, but if it doesn’t work, then why not get the source code and compile it with your project and just debug it on the site?

+1
source

I wanted to debug, because I had the impression that my rewriting rules did not work.

After a while, I realized that I needed to change my web.config and add the following line to the "system.web", "httpModules" section:

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

For those who want to log event messages in a file and also see them in the debug output window, here is a snippet of code that I created.

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

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

 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 } } } 
0
source

Source: https://habr.com/ru/post/1303955/


All Articles