Custom Logging
If you want to another logger than Serilog you can implement the IXLogger
interface. Doing so will override the default logger with your own.
Below you can see a simple sample that just have the warning level implemented.
using XSockets.Core.Common.Utility.Logging;
using System;
public class CustomLogger : IXLogger
{
public void Warning(string template, params object[] parmeters)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Warning: " + template, parmeters);
Console.ForegroundColor = ConsoleColor.White;
}
public void Warning(Exception ex, string template, params object[] parmeters)
{
throw new NotImplementedException();
}
public void Debug(string template, params object[] parmeters)
{
throw new NotImplementedException();
}
public void Debug(Exception ex, string template, params object[] parmeters)
{
throw new NotImplementedException();
}
public void Error(string template, params object[] parmeters)
{
throw new NotImplementedException();
}
public void Error(Exception ex, string template, params object[] parmeters)
{
throw new NotImplementedException();
}
public void Fatal(string template, params object[] parmeters)
{
throw new NotImplementedException();
}
public void Fatal(Exception ex, string template, params object[] parmeters)
{
throw new NotImplementedException();
}
public void Information(string template, params object[] parmeters)
{
throw new NotImplementedException();
}
public void Information(Exception ex, string template, params object[] parmeters)
{
throw new NotImplementedException();
}
public bool LevelEnabled(LogEventLevel level)
{
throw new NotImplementedException();
}
public void SetEventLevel(LogEventLevel level)
{
throw new NotImplementedException();
}
public void Verbose(string template, params object[] parmeters)
{
throw new NotImplementedException();
}
public void Verbose(Exception ex, string template, params object[] parmeters)
{
throw new NotImplementedException();
}
}
Testing
Testing the custom logger could look like this.
using System;
using XSockets.Core.Common.Utility.Logging;
using XSockets.Plugin.Framework;
class Program
{
static void Main(string[] args)
{
Composable.GetExport<IXLogger>().Warning("Just a test {0}", DateTime.Now);
Console.ReadLine();
}
}
Output
That would output