如何调试UrlRewriter.NET?

发布于 2024-08-25 02:57:17 字数 731 浏览 7 评论 0原文

我查看了他们的帮助页面,似乎我可以注册一个调试记录器,将信息输出到“标准 ASP.NET 调试窗口”。我的问题是我不知道这意味着什么,如果它意味着 Visual Studio 中的调试输出窗口(您可以在其中看到构建输出、调试输出等),我没有看到任何 UrlRewriter 调试输出。

规则(大部分)有效,我只是想获得更多调试输出来解决问题。

我将注册调用添加到重写器部分,如下所示:

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

我在 Vista 上的 IIS 中本地托管此网站,为了调试它,我将调试器附加到 w3wp 进程。

web.config 中的其他选定部分“

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

我应该在哪里看到 UrlRewriter.NET 的调试输出?如果它在 Visual Studio 调试输出窗口中,有什么想法为什么我在那里看不到它吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

信仰 2024-09-01 02:57:19

对于想要将事件消息记录到文件并在调试输出窗口中查看它们的人,这里是我创建的一段代码。

请仅在开发环境中使用此代码,此代码未优化。

用法:
在您的 asp.net 应用程序中,添加对此库 (MyPresentationLayer.Web) 的引用。
将以下元素添加到“重写器”节点:
<注册logger="IntelligenciaExt.Web.Logging.UrlRewriterIntelligencia.FileLogger, IntelligenciaExt.Web"/>
默认情况下,可以在“www”文件夹外部的子文件夹“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
     }
    } 
}

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
     }
    } 
}
提赋 2024-09-01 02:57:17

尝试运行 DebugView 来读取来自 Intelligencia.UrlRewriter 的消息

从这里获取
http://technet.microsoft.com/en-us/sysinternals/bb896647。 aspx

我看到源代码,我相信这是可行的,但如果不行,那么为什么不获取源代码,并用您的项目编译它,然后在现场调试它?

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 ?

月寒剑心 2024-09-01 02:57:17

我想进行调试,因为我的印象是我的重写规则不起作用。

一段时间后,我发现我必须更改 web.config 并将以下行添加到“system.web”、“httpModules”部分:

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

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"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文