I would like to implement logging in my application, but would rather not use any outside frameworks like log4net.
So I would like to do something like DOS's echo to a file. What is the most effective way to do it?
Is there a way to log unhandled exceptions logged without using an outside framework?
For more information MSDN:
If you want to stay close to .NET check out Enterprise Library Logging Application Block. Look here. Or for a quickstart tutorial check this. I have used the Validation application Block from the Enterprise Library and it really suits my needs and is very easy to "inherit" (install it and refrence it!) in your project.
If you want your own custom Error Logging you can easily write your own code. I'll give you a snippet from one of my projects.
Then to actually write to the error log just write (
q
being the caught exception)Why? Log4net would probably address most of your requirements. For example check this class: RollingFileAppender.
Log4net is well documented and there are thousand of resources and use cases on the web.
If you are looking for a real simple way to log, you can use this one liner. If the file doesn't exist, it's created.
You can write directly to an event log. Check the following links:
http://support.microsoft.com/kb/307024
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx
And here's the sample from MSDN: