0

I wrote this simple class in order to log a request properties:

public class Logger : ActionFilterAttribute
{
    private string logPath;

    public Logger()
    {
        System.Configuration.Configuration rootWebConfig =
            System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~\\web.config");
        logPath = rootWebConfig.AppSettings.Settings["logPath"].Value;
    }

    public override async System.Threading.Tasks.Task OnActionExecutingAsync(System.Web.Http.Controllers.HttpActionContext actionContext, System.Threading.CancellationToken cancellationToken)
    {
        await WriteLogAsync(actionContext);  
    }

    private async System.Threading.Tasks.Task WriteLogAsync(System.Web.Http.Controllers.HttpActionContext actionContext)
    {
        using (System.IO.StreamWriter file = new System.IO.StreamWriter(logPath, true))
        {
            await file.WriteLineAsync("==========================");
            await file.WriteLineAsync(DateTime.Now.ToString());
            await file.WriteLineAsync("URL: " + actionContext.Request.RequestUri);
            await file.WriteLineAsync("Headers: " + actionContext.Request.Headers);
            await file.WriteLineAsync("Content-type: " + actionContext.Request.Content.Headers.ContentType);
            await file.WriteLineAsync("Content: " + (await actionContext.Request.Content.ReadAsStringAsync())); **// Content is always empty**
            await file.WriteLineAsync("==========================");
        }
    }
}

The problem is in the marked line. The content is always an empty string although I'm sending an array like this: [118,119,120,122,123,24,19,20,21,22,23,124]

What am I missing here?

ronen
  • 1,460
  • 2
  • 17
  • 35

0 Answers0