geekbot/Geekbot.net/Lib/LoggerFactory.cs

27 lines
946 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-04-30 23:44:19 +02:00
public static ILogger CreateLogger()
{
2018-01-20 03:30:42 +01:00
var loggerCreation = new LoggerConfiguration();
var template = "{Message}{NewLine}";
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GEEKBOT_SUMO")))
{
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();
}
}
}