覆盖子目录 web.config 中的 system.diagnostics

发布于 2024-11-28 21:50:38 字数 2467 浏览 2 评论 0原文

我正在尝试为单个服务(此 IIS 应用程序中包含的多个服务之一)启用 WCF 消息跟踪。我创建了一个 web.config 文件,并将其放置在与 .svc 文件相同的物理目录中。我可以从此 web.config 文件配置服务,修改行为、端点等。但是,当我尝试包含 system.diagnostics 节点时,它似乎没有效果。这不会生成跟踪文件:

<?xml version="1.0"?>
<configuration>
    <system.serviceModel>    
        <services>
            <service name="My.Awesome.Wcf.Service" />
            <!-- my endpoints and behaviors are defined programmatically -->
        </services>

        <diagnostics>
            <messageLogging
                 logEntireMessage="true"
                 logMalformedMessages="true"
                 logMessagesAtServiceLevel="true"
                 logMessagesAtTransportLevel="true"
                 maxMessagesToLog="3000" />
        </diagnostics>
    </system.serviceModel>

    <system.diagnostics>
        <sources>
            <source name="System.ServiceModel"
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true" >
                <listeners>
                    <add name="xml"/>
                </listeners>
            </source>
            <source name="System.ServiceModel.MessageLogging">
                <listeners>
                    <add name="xml"/>
                </listeners>
            </source>
        </sources>
        <sharedListeners>
            <add name="xml"
                 type="System.Diagnostics.XmlWriterTraceListener"
                       initializeData="C:\logs\Traces.svclog" />
        </sharedListeners>
        <trace autoflush="true" />
    </system.diagnostics>
</configuration>

如果我将整个 system.diagnostics 节点从该子目录 web.config 移至应用程序的根 web.config,那么它就会神奇地开始工作。据我所知,system.diagnostics 部分不限于应用程序的根 web.config,因为我的 machine.config 显示了此部分定义:

<section name="system.diagnostics" type="System.Diagnostics.SystemDiagnosticsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

请注意,此定义不包含“allowDefinition”属性,根据section 元素的 MSDN 文档 意味着它可以被定义为“任何地方”其中应该包括物理子目录。我也无法在任何父 web.config 中找到任何 system.diagnostics 定义。

有谁知道为什么这个 system.diagnostics 配置可能无法得到处理?

I am attempting to enable WCF message tracing for a single service (one of several included in this IIS application). I have created a web.config file that is placed in the same physical directory as my .svc file. I am able to configure the service from this web.config file, modifying behaviors, endpoints etc. However, when I attempt to include the include a system.diagnostics node, it appears to have no effect. This does not produce a trace file:

<?xml version="1.0"?>
<configuration>
    <system.serviceModel>    
        <services>
            <service name="My.Awesome.Wcf.Service" />
            <!-- my endpoints and behaviors are defined programmatically -->
        </services>

        <diagnostics>
            <messageLogging
                 logEntireMessage="true"
                 logMalformedMessages="true"
                 logMessagesAtServiceLevel="true"
                 logMessagesAtTransportLevel="true"
                 maxMessagesToLog="3000" />
        </diagnostics>
    </system.serviceModel>

    <system.diagnostics>
        <sources>
            <source name="System.ServiceModel"
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true" >
                <listeners>
                    <add name="xml"/>
                </listeners>
            </source>
            <source name="System.ServiceModel.MessageLogging">
                <listeners>
                    <add name="xml"/>
                </listeners>
            </source>
        </sources>
        <sharedListeners>
            <add name="xml"
                 type="System.Diagnostics.XmlWriterTraceListener"
                       initializeData="C:\logs\Traces.svclog" />
        </sharedListeners>
        <trace autoflush="true" />
    </system.diagnostics>
</configuration>

If I move the entire system.diagnostics node out of this sub-directory web.config to the application's root web.config, then it magically starts working. As far as I can tell, the system.diagnostics section is not limited to the application's root web.config, since my machine.config shows this section definition:

<section name="system.diagnostics" type="System.Diagnostics.SystemDiagnosticsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

Note that this definition does not include an "allowDefinition" attribute, which, according to this MSDN documentation for the section element means that it can be defined "Everywhere" which should include physical subdirectories. I have not been able to find any system.diagnostics definitions in any parent web.configs either.

Does anyone know why this system.diagnostics configuration might not be getting processed?

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

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

发布评论

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

评论(3

殤城〤 2024-12-05 21:50:38

结束这个问题:真正的问题是为什么要在子文件夹级别指定 WCF 日志记录?

WCF 托管位于 IIS 应用程序级别。您不能对根 URL 处的服务禁用 WCF 日志记录,然后在较低级别启用。如果你想模拟这种场景,那么你需要 2 个 WCF 应用程序,一个在另一个中(在 IIS 中);在 .NET 中,它们是 2 个独立的 AppDomain。

如果您更愿意坚持使用一个 AppDomain,那么您也许可以通过创建消息过滤器来实现您想要实现的目标。请参阅 msdn 中的“邮件筛选器”。

To close out this question: the real question is why would you want to specify WCF logging at a sub-folder level?

WCF hosting is at the IIS Application level. You can't have WCF logging disabled for services at the root URL then enabled at lower levels. If you want to emulate such scenario, then you need 2 WCF applications, one within the other (in IIS); in .NET, they are 2 separate AppDomains.

If you prefer to stick to one AppDomain, then you can perhaps achieve what you are trying to accomplish to by creating message filters. See "Message Filters" in msdn.

墨落成白 2024-12-05 21:50:38

试试这个:-

    <sources>
        <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
            <listeners>
                <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\temp\Traces.svclog" />
            </listeners>
        </source>
    </sources>

Try this:-

    <sources>
        <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
            <listeners>
                <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\temp\Traces.svclog" />
            </listeners>
        </source>
    </sources>
心如荒岛 2024-12-05 21:50:38

C:\logs\ 是否存在?如果没有,则根本不会创建日志文件。

Does C:\logs\ exist? If it doesn't, the log file will not get created at all.

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