The correct way to receive a request. Content from the global error handler

I registered a global exception handler and it starts and contains all the information I need, except Request.Content, which is always empty ... I need the values ​​that were passed when I debug ...

Public class MyExceptionLogger : ExceptionLogger
    {
        public override void Log(ExceptionLoggerContext context)
        {

            try
            {
                 ... other code

            var methodName = context.Request.Method.ToString();
            var errorUri = context.Request.RequestUri.ToString();
            var errorMessage = context.Exception.Message;
            var errorStackTrace = context.Exception.StackTrace.ToString();

            var payload = context.Request.Content.ReadAsStringAsync().Result;

            .....  other code  

            }

       }
   }

What is the correct way to get Request.Content from the global error handler? In the above code, the Content property has already been read by the model binding and as such is always empty.

How can I consistently get a published body from an exception?

Should I get and save the published body in a custom MessageHandler?

Thanks Greg

+4
source share
1

. . , :

var payload = context.Request.Content.ReadAsStringAsync().Result;

... , , ... , !

+1

Source: https://habr.com/ru/post/1570007/


All Articles