Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So I will assume your goal for the logging is, as it should be, to debug the application rather than measure for performance.</p> <p>While I think there is no one 'right' answer to this, at the minimum I would always try to log</p> <p><li>Timestamps, class/function names and thread name (if yr running a multithreaded app) in every log line</p> <p><li>Quick log line @ every entry point, along with the full contents of the passed in request, preferably in a format that would make it easier for you to reissue the same request from fiddler or a similar tool (this can be done via a custom action filter - <a href="https://www.simple-talk.com/dotnet/performance/building-performance-metrics-into-asp.net-mvc-applications/">see how the author uses these for performance monitoring a web api app here</a> )</p> <p><li>If you are doing any database queries as part of your action, log the full query sql string if possible (once again to make it easier to repeat during debugging) as well as at least the # of rows returned</p> <p><li> If you are doing any external service calls, log both the full request and response strings</p> <p><li>Use try/catch blocks to log any exceptions (you can also use something like the ELMAH library to do this automatically rather than handling in code - <a href="https://code.google.com/p/elmah/">link here</a> and <a href="http://blogs.msdn.com/b/webdev/archive/2012/11/16/capturing-unhandled-exceptions-in-asp-net-web-api-s-with-elmah.aspx?Redirected=true">here</a></p> <p><li> Anything that is resolved during runtime - think values from config files, database queries, calculated values, should also be logged</p> <p>I'm sure there is more missing from this list - after all this varies on what yr doing in the app. You should be asking yourself at every step of the way - what could go wrong in my application? What things would I or the poor chap that will work on this after me find useful whilst debugging a problem? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload