Logging is the generic term for recording information - tracing is the specific form of logging used to debug.
In .NET the System.Diagnostics.Trace and System.Diagnostics.Debug objects allow simple logging to a number of "event listeners" that you can configure in app.config. You can also use TraceSwitches to configure and filter (between errors and info levels, for instance).
private void TestMethod(string x)
{
if(x.Length> 10)
{
Trace.Write("String was " + x.Length);
throw new ArgumentException("String too long");
}
}
In ASP.NET, there is a special version of Trace (System.Web.TraceContext) will writes to the bottom of the ASP page or Trace.axd.
In ASP.NET 2+, there is also a fuller logging framework called Health Monitoring.
Log4Net is a richer and more flexible way of tracing or logging than the in-built Trace, or even ASP Health Monitoring. Like Diagnostics.Trace you configure event listeners ("appenders") in config. For simple tracing, the use is simple like the inbuilt Trace. The decision to use Log4Net is whether you have more complicated requirements.
private void TestMethod(string x)
{
Log.Info("String length is " + x.Length);
if(x.Length> 10)
{
Log.Error("String was " + x.Length);
throw new ArgumentException("String too long");
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…