[英]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.