I am wondering about what the difference between logging and tracing is.
Is the difference basically that tracing is more detailed log giving developers a tool to debug applications at runtime?
I have been experimenting with log4net and doing logging. Now I am wondering if I should be doing tracing as well and if I could/should use log4net for that purpose. Should I be doing tracing with log4net and is there some trace level for log4net loggers? Should I use a different log level for debug and trace purposes or is it ok to use the same? Can you give a simple example on how I would do logging and tracing for a simple method?
Edit: Despite a few helpful answers below I am still unsure how I should be doing tracing versus logging.
I have the following method in my Business layer and I want to add logging/tracing to it. I am wondering how to do it efficiently. Is the following method acceptable in terms of logging/tracing? Should the log messages be of type Info instead of Debug? Are the Debug messages I am logging considered trace? How would you change it?
IEnumerable<Car> GetCars()
{
try
{
logger.Debug("Getting cars");
IEnumerable<Car> cars = CarAccessor.GetCars().ConvertAll(DataAccessToBusinessConverter);
logger.Debug("Got total of " + cars.Count + " cars");
} catch (Exception e) {
logger.Error("Error when getting cars", e);
throw new Exception("Unexpected error when getting cars");
}
}
See Question&Answers more detail:os