It seems in my code Elmah and Nlog don't log all my Web API errors. Here is an example that all C# Web API developer know:
[Authorize]
public class ValuesController : ApiController
{
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
public string Get(int id)
{
return "value";
}
// POST api/values
public void Post([FromBody]string value)
{
}
// PUT api/values/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
public void Delete(int id)
{
}
}
When I go to my browser and GET http://localhost:55328/api/Values/5 I receive this message:
<Error>
<Message>Authorization has been denied for this request.</Message>
</Error>
Fine but when I go to http://localhost:55328/elmah.axd Elmah doesn't log this error. I also don't know how force the log with NLog. And yes Elmah and NLog are working fine when the error happens inside the body of a method.