I have seen a fair amount of discussions on this topic. Everybody knows what the logging is, but most of the people get confuse when to log and what to log. One of my friends started this conversation and we finally came up with Guide lines to do logging in a web application. I thought to share them, so here it goes.
I believe and this is coming from coding in .net 1.0 before VS was available. Debug logging should be good enough to provide us exactly how the code had flown in its execution to allow tracing the debug path. Below are guidelines that we decided (for debug)
- Each log statement should exactly tell us where exactly in the code this log was written. This is best done by having log identifiers which should be of format
- Time : By Default
- Machine Name : By Default
- Session Id : By Default
- Class Name : By Default
- Method Name : From our log message
- Id within method : From our log message
- The message
So a message could look like 2011-09-30 10:20:55 224 ~ Machine1~ewhfiwehfoiwe~ MyProject.DAL.MyDalClass ~ CreateUser ~ Start~ UserName=uywieyrw, Passowrd=wehfdiw
- Log elements should be separated by a ~. We could use any other thing but I prefer ~ because it is a very uncommon character thus opening it in excel will make life very easy.
- We should not log in a loop as far as possible; we should however log number of times a loop was executed.
- We should always log the then and else part of a log.
- We are told that whenever we enter a method and exit from a method that should be logged. I have realized logging the arguments which are received by that method is more helpful. Similarly one can also log return values.
- Whenever inside a method you call another function and receive any data that data should be logged.
- Whenever you are contacting external resource and exchanging some data then, data sent and received should be logged. E.g. whenever there is a web service call or server to server post, the data sent and received should be logged as Info Logs.
- Finally anything going into the database and sp executed should be logged.
The best way to learn logging is not using VS for debugging and instead relying upon logs. You will end up writing best debug logs which will be helpful in production debugging.

As I web site possessor I believe the content material here is rattling excellent , appreciate it for your efforts. You should keep it up forever! Good Luck.
Thank you
Your design is so exclusive in comparison to a lot of others. Thanks for publishing whenever you possess the possibility,Guess I’ll just make this bookmarked.two
Thanks
This web site is certainly relatively helpful considering that I’m with the second developing a web floral site – even though I’m only beginning out as a result it is truly relatively tiny, practically nothing such as this website. Can hyperlink to some with the posts right here because they are really. Many thanks considerably. Zoey Olsen
I would really like to say thanks so much for that job you have made in writing this piece of writing. I am hoping the same most reliable work from you in the future also.
It is always difficult to get advised persons on that topic, however you seem like you no doubt know what you are writing on! Thanks a lot