문제

I'm searching for a feature to enable loggin/tracing in ASP.NET MVC 4 Web Api. In WCF you can activate logging and WCF writes that it is doing. Then, I can open the dump and search for errors.

I do not want to trace my web api but log that the framework is doing. If i trace/log the web api with message handlers I get no information if an error occures before my implementation.

도움이 되었습니까?

해결책

I'd recommend two things.

1) To get full detail of on thrown exceptions, I'd set the error policy to always. This should return more detail exception messages from your code.

  GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

I think this only works in RC though.

2) Then I would also suggest wiring up a message handler that you can use to extra request/ response info. The message handlers will run when new requests come in and just before the final responses return. There are tons of examples of this online. WebAPIContrib has one in it's GitHub repo you can take a look at as an example

3) If you want to monitor other server events, you may want to consider using asp.net health monitoring, as long as you're hosting in asp.net of course. It'll allow you to do various audits and monitor server errors.

다른 팁

See http://www.asp.net/web-api/overview/testing-and-debugging/tracing-in-aspnet-web-api

If you provide an ITraceWriter implementation (which can be as simple as calling System.Diagnostics.Trace), the web API framework will trace what it does.

  • Mike
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top