【问题标题】:ASP.NET: How can I use a listener defined on Web.Config?ASP.NET:如何使用 Web.Config 上定义的侦听器?
【发布时间】:2011-01-21 11:00:24
【问题描述】:

我正在使用 Visual Studio 2008 SP1 和 C# 开发一个 ASP.NET WebForm 应用程序。

我在 Web.Config 上定义了以下监听器:

<system.diagnostics>
    <trace>
        <listeners>
            <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="D:\Logs\logWeb.txt" />
        </listeners>
    </trace>
</system.diagnostics>

如何将输出从 OutPut Window 重定向到此侦听器?所有的句子都是这样的:

System.Diagnostics.Trace.WriteLine("IntegratedManaged: ResolveCulture");

System.Diagnostics.Debug.WriteLine("IntegratedManaged: ResolveCulture");

显示在输出窗口中。

【问题讨论】:

    标签: c# asp.net logging webforms system.diagnostics


    【解决方案1】:

    我解决了这个问题。现在,Web.Config 看起来像这样:

    <system.diagnostics>
        <trace autoflush="true" indentsize="2">
            <listeners>
                <remove name="Default" />
                <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="D:\Logs\logWeb.txt" />
            </listeners>
        </trace>
    </system.diagnostics>
    

    需要移除默认监听器。

    【讨论】:

      【解决方案2】:

      一篇不错的文章是here

      如果你想监听 asp.net 应用程序的 WMI 事件,请参考this

      【讨论】:

        猜你喜欢
        • 2023-04-10
        • 1970-01-01
        • 2021-04-23
        • 2021-03-03
        • 1970-01-01
        • 1970-01-01
        • 2014-02-12
        • 1970-01-01
        • 2015-11-30
        相关资源
        最近更新 更多