EasyLog is a simple logging tool for for the .Net framework, and is designed to be easy to use, easy to configure and easy to extend.
1. Easy to Use
Code just like :
Log.Debug("Debug Message"); //write a debug level message
Log.Error("Error Message"); //write a error level message
Log.Error("Error Message", ex); //write a error level message and log the exception
Log.LogMessage("Error Message", Level.Error); //write a message with specipfy level
Log.LogMessage("Fatal Message", Level.Fatal, ex);//write a message with specipfy level and log the
2. Easy to Configurate
Default it is not need to configurate.
The default configuration is:
EasyLog.LogLevel is Error.
EasyLog.LogType is EasyLog.FileLog type.
EasyLog.FileLog.FilePathFormat is "~/log/{0:yyyy-MM-dd}.log", it will generate one log file per day.
EasyLog.FileLog.MaxLogLength is 10M, it will limit the content length to 10M.
It is suitable for deployment.
Below is equal configuration in application configuration file
3. Easy to Extend
See How to Extend it?
4. Configurable at runtime without modifying the application binary.
it use appSettings to store configuration in application configuration file. it is optional, you can change it.
5. Filter the message by level
level: DEBUG < INFO < WARN < ERROR < FATAL
Default level is error, it will filter debug, info and warn level message.
6. How to Extend it?
it is easy to extend it, add a class that implemented the interface ILog, and configure it in the appSettings just like
Example usage:
using EasyLog;
using System.Collections.Specialized;
namespace EasyLogTest
{
public class ConsoleLog : ILog
{
public void ConfigLogger(NameValueCollection properties)
{
}
public void LogMessage(object message, Level level, Exception ex)
{
StringBuilder messageBuilder = new StringBuilder();
FormatMessage(messageBuilder, message, level, ex);
Console.Write(messageBuilder);
}
public void FormatMessage(StringBuilder builder, object message, Level level, Exception e)
{
builder.Append("\tConsoleLog ");
builder.Append(DateTime.Now);
builder.Append((" [" + level.ToString().ToUpper() + "] ").PadRight(9));
builder.Append(message);
if (e != null)
{
builder.Append(Environment.NewLine).Append(e.ToString());
}
builder.AppendLine();
}
}
}
Questions & Comments