Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a windows application using C#.net (4.5) I am asked to create a Debug Log for my software. How can I create it ?? Should I put debug log code after each line ??
Posted
Comments
Ashok G Patel 13-Mar-14 7:35am    
If you want to create a Debug Log at each line than
Just create one text file on specific location and write the execution detail on code in that file.

Ex .
private static void Main(string[] args)
{
int a = 10, b = 20;
int sum = a + b;

WriteToErrorLog("value of {0}", a);
WriteToErrorLog("value of {0}", b);
WriteToErrorLog("value of {0}", sum);

Console.Write("{0}", sum);

WriteToErrorLog("value of {0}", sum);
}

In WriteToErrorLog(string log) write the content in one particular file to maintain your log

No, you should write in the log only the important notifications about the execution path, and this depends on your application.
 
Share this answer
 
Comments
Marcin Kozub 13-Mar-14 10:18am    
As Raul mention above it depends on your application. Debugging is proces to help you find and reduce errors in your application, but it can be used to log flow of your program as well. You can output any kind of messages to your log, and you should to group them by some levels. Sample levels of debugging:
Debug - output variable/parameters values
Information - not very important messages
Warning - there was some problem but program can continue to work
Error - there was an errror and program cannot continue.

Simple lines of debug file could look something like this:
2014-03-13 15:15 - Debug - ContactManager.GetContactByID, Input parameter: ID = 4512
2014-03-13 15:15 - Warning - ContactManager.SaveContact, Input parameter ID has value out of range: 9999. Setting to default: 0

These are just examples. Take a look at this library and read its documentation: http://nlog-project.org/
You could use log4net - very powerful logging tool....

[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900