To create a custom target, inherit from the BaseTarget and then add the target to the Log.Config.Targets collection. Example of a Custom ConsoleTarget
public class MyCustomTarget : BaseTarget
{
public MyCustomTarget()
{
Name = "MyCustomTarget";
}
public override bool LogMessage(LogEntry entry)
{
Console.WriteLine(FormatMessage(entry));
return true;
}
}
Log.Config.Targets(new MyCustomTarget());
To create a file target, inhert from the BaseFileTarget and then add the target to the Log.Config.Targets collection. Example of a custom FileTarget:
public class MyCustomFileTarget : BaseFileTarget
{
public MyCustomFileTarget()
{
Name = "MyCustomFileTarget";
}
public MyCustomFileTarget(string path)
: base(path)
{
Name = "MyCustomFileTarget";
}
protected override string Extension
{
get
{
return ".txt";
}
}
protected override void ProcessLine()
{
CurrentLine = FormatMessage(CurrentEntry);
}
}