【问题标题】:Why do I get the error "The service type ITraceWriter is not supported." from Azure?为什么我会收到错误“不支持服务类型 ITraceWriter”。来自天青?
【发布时间】:2016-12-12 21:16:59
【问题描述】:

我正在尝试在 Azure 应用服务上启动并运行我的 Web API 2。它在我的机器上运行良好,在 IIS 10 上,添加了以下跟踪,来自包 Microsoft.AspNet.WebApi.Tracing

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.EnableSystemDiagnosticsTracing();
        SystemDiagnosticsTraceWriter traceWriter = config.EnableSystemDiagnosticsTracing();
        traceWriter.IsVerbose = true;
        traceWriter.MinimumLevel = TraceLevel.Debug;
        config.Services.Add(typeof(ITraceWriter), new TextFileTracer());

这在我的开发机器上运行良好,但出现错误

不支持服务类型 ITraceWriter。

我一发布到 Azure。我认为现代 ASP.NET 应用程序应该是自包含的,而不依赖于主机上存在或配置的服务,并且是一个非常最新的主机。为什么会这样?

【问题讨论】:

    标签: c# asp.net azure asp.net-web-api


    【解决方案1】:

    根据您的描述,我在我的 Web API 应用程序上测试了您的代码,我在本地收到如下服务器错误。

    不支持服务类型 ITraceWriter。 参数名称:服务类型

    正如这个官方document提到的关于设置Trace Writer:

    要启用跟踪,您必须配置 Web API 以使用您的 ITraceWriter 实现。您可以通过 HttpConfiguration 对象执行此操作,如下代码所示:

    config.Services.Replace(typeof(ITraceWriter), new TextFileTracer());

    只能激活一个跟踪写入器。默认情况下,Web API 设置了一个“无操作”跟踪器,它什么都不做。 (存在“no-op”跟踪器,因此跟踪代码不必在写入跟踪之前检查跟踪编写器是否为空。)

    TextFileTracer 实例替换ITraceWriter 服务后,我可以让它在我这边和Azure 上都按预期工作。

    【讨论】:

      猜你喜欢
      • 2019-11-23
      • 2013-07-17
      • 2021-01-21
      • 2017-01-04
      • 1970-01-01
      • 1970-01-01
      • 2022-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多