简体   繁体   English

为什么我会从Azure收到错误消息“不支持ITraceWriter服务类型。”

[英]Why do I get the error “The service type ITraceWriter is not supported.” from Azure?

I am trying to get my Web API 2 up and running on an Azure App Service. 我正在尝试启动Web API 2并在Azure应用服务上运行。 It works fine on my machine, on IIS 10, with the following tracing added, from the package Microsoft.AspNet.WebApi.Tracing : 它在我的机器上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());

This works fine on my dev machine, but I get the error 这在我的开发机上工作正常,但出现错误

The service type ITraceWriter is not supported. 不支持服务类型ITraceWriter。

as soon as I publish to Azure. 我一发布到Azure。 I thought a modern ASP.NET app was supposed to be self contained, and not rely on services being present or configured on the host, and a very up to date host at that. 我认为现代的ASP.NET应用程序应该是自包含的,而不是依赖主机上存在的或配置的服务以及当时最新的主机。 Why is this happening? 为什么会这样呢?

According to your description, I tested your code on my Web API application and I got the server error as follows on my local side. 根据您的描述,我在Web API应用程序上测试了您的代码,并在本地收到了以下服务器错误。

The service type ITraceWriter is not supported. 不支持服务类型ITraceWriter。 Parameter name: serviceType 参数名称:serviceType

As mentioned in this official document about setting the Trace Writer: 如本正式文档中有关设置跟踪编写器所述:

To enable tracing, you must configure Web API to use your ITraceWriter implementation. 要启用跟踪,必须将Web API配置为使用ITraceWriter实现。 You do this through the HttpConfiguration object, as shown in the following code: 您可以通过HttpConfiguration对象执行此操作,如以下代码所示:

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

Only one trace writer can be active. 只能有一个跟踪编写器。 By default, Web API sets a "no-op" tracer that does nothing. 默认情况下,Web API设置不执行任何操作的“无操作”跟踪程序。 (The "no-op" tracer exists so that tracing code does not have to check whether the trace writer is null before writing a trace.) (存在“ no-op”跟踪程序,因此跟踪代码在写入跟踪之前不必检查跟踪编写器是否为空。)

After replacing ITraceWriter service with the TextFileTracer instance, I could make it work as expected both on my side and Azure. TextFileTracer实例替换ITraceWriter服务后,我可以使它在我这方面和Azure都能按预期工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure媒体服务-3gp文件返回错误“文件类型或编解码器不支持。” - Azure Media Services - 3gp file returns error “File type or codec not supported.” 不支持服务类型IAssembliesResolver。 参数名称:serviceType - The service type IAssembliesResolver is not supported. Parameter name: serviceType 为什么从 azure 应用程序服务中的表单发布时出现 404 错误,但它在 localhost 中完美运行 - Why do i get 404 error when posting from form in azure app service but It works perfectly in localhost 为什么为什么不断收到“不支持其类型为原始类型集合或复杂类型的属性。”? - Why do I keep getting “ Properties whose types are collection of primitives or complex types are not supported.”? Azure文件存储:错误400(不支持条件标头。) - Azure File Storage: Error 400 (Condition headers are not supported.) 不支持对两个大型LINQ查询进行联合。 我如何解决(如果可能的话) - Union on two big LINQ queries not supported. How do I get around it (if at all possible) 依赖注入:类型SimpleTraceWriter必须从ITraceWriter派生 - Dependency Injection: The type SimpleTraceWriter must derive from ITraceWriter System.ArgumentException:'不支持服务类型ICommand。 参数名称:serviceType - System.ArgumentException: 'The service type ICommand is not supported. Parameter name: serviceType 为什么我在调用 web 服务时收到此错误,在序列化 object 类型时检测到循环引用? - Why do i get this error while calling a web service that a circular reference was detected while serializing an object of type? 如何避免“不支持嵌套事务”。 错误? - How to avoid a “Nested transactions are not supported.” error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM