Public HttpResponseMessage GetAllProducts()Ĭ().Info( Public class ProductsController : ApiController You can also use the trace writer to trace your own code: using
Trace levels, in order, are Debug, Info, Warn, Error, and Fatal.Īdding Traces to Your Web API ApplicationĪdding a trace writer gives you immediate access to the traces created by the Web API pipeline. MinimumLevel: Sets the minimum trace level.If true, traces include more information. IsVerbose: If false, each trace contains minimal information.There are two settings that you can control: TraceWriter.MinimumLevel = TraceLevel.Debug SystemDiagnosticsTraceWriter traceWriter = config.EnableSystemDiagnosticsTracing()
Itrace project how to#
The following code shows how to configure the trace writer. For more information about trace writers, see the Trace Listeners topic on MSDN. (From the View menu, select Output).īecause SystemDiagnosticsTraceWriter writes traces to, you can register additional trace listeners for example, to write traces to a log file. The trace statements are written to the Output window in Visual Studio. To see the traces, run the application in the debugger. The SystemDiagnosticsTraceWriter class writes traces to. This code adds the SystemDiagnosticsTraceWriter class to the Web API pipeline. Public static void Register(HttpConfiguration config) Add the following code to the Register method. Open the file WebApiConfig.cs in the App_Start folder.
Itrace project install#
If you want to target a specific version of Web API, use the -Version flag when you install the tracing package. The second command updates the WebApi.WebHost package to the latest version. It also updates the core Web API packages. The first command installs the latest Web API tracing package. In the Package Manager Console window, type the following commands. Under Templates, Web, select ASP.NET Web Application.įrom the Tools menu, select NuGet Package Manager, then Package Manage Console. In Visual Studio, from the File menu, select New > Project. Visual Studio 2017 (also works with Visual Studio 2015)Įnable System.Diagnostics Tracing in Web APIįirst, we'll create a new ASP.NET Web Application project.You can also use it to trace your own code. You can use this feature to trace what the Web API framework does before and after it invokes your controller. This tutorial shows how to enable tracing in ASP.NET Web API. When you are trying to debug a web-based application, there is no substitute for a good set of trace logs.