geekbot/Geekbot.net/Lib/LoggerFactory.cs

27 lines
908 B
C#
Raw Normal View History

using System;
using Serilog;
2018-01-20 03:30:42 +01:00
using Serilog.Sinks.SumoLogic;
namespace Geekbot.net.Lib
{
public class LoggerFactory
{
2018-05-01 16:50:48 +02:00
public static ILogger CreateLogger(bool sumologicActive)
{
2018-01-20 03:30:42 +01:00
var loggerCreation = new LoggerConfiguration();
var template = "{Message}{NewLine}";
2018-05-01 16:50:48 +02:00
if (sumologicActive)
{
2018-01-20 03:30:42 +01:00
Console.WriteLine("Logging Geekbot Logs to Sumologic");
loggerCreation.WriteTo.SumoLogic(Environment.GetEnvironmentVariable("GEEKBOT_SUMO"),
outputTemplate: template);
}
else
{
2018-01-20 03:30:42 +01:00
loggerCreation.WriteTo.LiterateConsole(outputTemplate: template);
loggerCreation.WriteTo.RollingFile("Logs/geekbot-{Date}.txt", shared: true, outputTemplate: template);
}
return loggerCreation.CreateLogger();
}
}
}