How should I log exceptions? I never tried logging in .NET before. Nor try to dump exceptions to a txt (or binary) file. I dont require a text file, just a way to view the logs with the file and line #.
-edit- using asp.net
How should I log exceptions? I never tried logging in .NET before. Nor try to dump exceptions to a txt (or binary) file. I dont require a text file, just a way to view the logs with the file and line #.
-edit- using asp.net
For logging exceptions, check out the project: ELMAH
For other types of logging, you can't go past Log4Net.
NLOG looks good .. but does it just log general messages .. not Exceptions ..? or is that what an InfoException is? e.g. in debug mode you might want to count and log the number of times a loop is iterated...
Also has anyone else had difficulty unzipping the Log4Net downloads on http://logging.apache.org/log4net/download.html
ELMAH is particularly nice if you're using ASP.NET. One of my favorite features about ELMAH is not having to build the UI to view logged exceptions; ELMAH provides a handler that will report your exceptions. However, I've never used it for logging anything other than exceptions.
log4net, and Microsoft's EntLib are some other ideas that come to mind. These provide a lot more functionality than what you may need if all you really need is just exception logging.
Also, you may consider performance counters if what you're really trying to do is measure your application. Again, the benefit of using performance counters is that after publishing the data, you won't have to worry about build the UI to view/query the data.
It seems you're quite new to the programming and recently tried to figure out more advanced topics. If you're just interested to see the file and line# of the exception, then you certainly no need to use any logging utility such as Log4net or Microsoft Enterprise Library.
Now onwards, start putting your code in try-catch block and handle exceptions (if any) in catch block.
Here in exception, you can find stack trace, which will give you an exact idea of which method and line you code failed.
Hope this helps.
log4net is quite a beautiful and standard system to use. Well worth learning, and you can log to a variety of formats (or custom). (Edit: However, as far as I know, it's not supported on Silverlight yet, if that interests you, so you may need to implement your own system there).
The enterprise library logging application block is one option. It might be more than you need (or less), but it has worked well for me.