Error logging in C#

Posted by rschuler on Stack Overflow See other posts from Stack Overflow or by rschuler
Published on 2008-09-29T04:53:55Z Indexed on 2010/05/11 8:14 UTC
Read the original article Hit count: 269

Filed under:
|
|

I am making my switch from coding in C++ to C#. I need to replace my C++ error logging/reporting macro system with something similar in C#.

In my C++ source I can write

LOGERR("Some error"); or LOGERR("Error with inputs %s and %d", stringvar, intvar);

The macro & supporting library code then passes the (possibly varargs) formatted message into a database along with the source file, source line, user name, and time. The same data is also stuffed into a data structure for later reporting to the user.

Does anybody have C# code snippets or pointers to examples that do this basic error reporting/logging?

Edit: At the time I asked this question I was really new to .NET and was unaware of System.Diagnostics.Trace. System.Diagnostics.Trace was what I needed at that time. Since then I have used log4net on projects where the logging requirements were larger and more complex. Just edit that 500 line XML configuration file and log4net will do everything you will ever need :)

© Stack Overflow or respective owner

Related posts about c#

Related posts about error-logging