Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created webApi global exception handler, i have to log the request parameters/JSON in the prod environment to verify the request if any exception happened, Please let me know the way to log the request message with in the
ExceptionHandler
.

WebApiConfig

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.Services.Replace(typeof (IExceptionHandler), 
            new GlobalExceptionHandler());
    }
}


GlobalExceptionHandler


public class GlobalExceptionHandler : ExceptionHandler
{
    public override void Handle(ExceptionHandlerContext context)
    {
	 Logger.log("Exception : \t" + context.Exception.Message)
         Logger.log("Request JSON : \t" + Josn.Serializer(context.Request.Content));
    }
}


What I have tried:

i tried to get the JSON from
ExceptionHandlerContext 
Posted
Updated 20-Feb-18 22:54pm

1 solution

String data;
Using (var stream = ExceptionHandlerContext.Request.content.ReadAsStreamAsync().result )
{
if(stream.CanSeek)
{
stream.Position = 0;
}
data = ExceptionHandlerContext.Request.content.ReadAsStreamAsync().result
}

JsonConvert.DeserializObject<Dictionary<string,string>>(data)

using NewtonSoft.Json
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900