asp.net web api - Web API ExceptionLogger -
I'm using IExceptionLogger and Exception handler to address logging and error globally for my web API service.
Now there is no way to read post data from the exception logo contact context. ? Just because I want to save the post data with exception details.
ExceptionLoggerContext.ExceptionContext to parse The only way I found
ExceptionLoggerContext.ExceptionContext in your ExceptionLogger / IExceptionLogger implementation. Type is System.Web.Http. Exception Handling.ExceptionContext . Some nested objects that you have to navigate, but at some point, you'll find:
((System.Web .Http.ApiController) exceptionContext.ControllerContext.Controller ) .ActionContext.ActionArguments that happens with all the arguments in a ValueCollection form of your My In the solution I have implemented something like this.
public class MyExceptionContext {public dictionary & lt; String, Object & gt; .ValueCollection ActionArguments {get; Set; } Public MyExceptionContext (System.Web.Http.ExceptionHandling.ExceptionContext exceptionContext) {try {this.ActionArguments = ((System.Web.Http.ApiController) exceptionContext.ControllerContext.Controller) .ActionContext.ActionArguments.Values; } Hold (exception) {}}} I pass my Creator ExceptionLoggerContext.Exception Context ; It will populate the dictionary ActionArguments with all values. You can find one on Github. This self-hosted (Owen) web. In my API application I have defined my custom implementation of IExceptionLogger and IExceptionHandler . In this sample app I have used serialog for the exception of the stream on the disk. If you test controller will be trapped by the attempt to form posts, which is a global handler and remains on the file system with some information
If you download the examples were found in Github and run you can use Fiddler to this test:
POST http: // Localhost: 9667 / api / exception HTTP / 1.1 User-agent: Fiddler content type: application / x-www form-urlencoded host: Aniy Host: 9667 Content-Length: 40 username = stackoverflow & amp; Password = password
Comments
Post a Comment