Log everything to sumologic
This commit is contained in:
parent
07ca1e1548
commit
751c164c82
3 changed files with 21 additions and 15 deletions
|
@ -25,10 +25,11 @@
|
|||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
<PackageReference Include="Overwatch.Net" Version="3.0.0" />
|
||||
<PackageReference Include="PokeApi.NET" Version="1.1.0" />
|
||||
<PackageReference Include="Serilog" Version="2.6.0-dev-00894" />
|
||||
<PackageReference Include="Serilog" Version="2.6.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1-dev-00757" />
|
||||
<PackageReference Include="Serilog.Sinks.Literate" Version="3.0.1-dev-00044" />
|
||||
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.1-dev-00771" />
|
||||
<PackageReference Include="Serilog.Sinks.SumoLogic" Version="2.3.0" />
|
||||
<PackageReference Include="SharpRaven" Version="2.2.0" />
|
||||
<PackageReference Include="StackExchange.Redis">
|
||||
<Version>1.2.6</Version>
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog;
|
||||
using Utf8Json;
|
||||
using Utf8Json.Formatters;
|
||||
using Utf8Json.Resolvers;
|
||||
|
||||
namespace Geekbot.net.Lib
|
||||
{
|
||||
public class GeekbotLogger : IGeekbotLogger
|
||||
{
|
||||
private readonly ILogger _serilog;
|
||||
public GeekbotLogger()
|
||||
{
|
||||
JsonSerializer.SetDefaultResolver(StandardResolver.AllowPrivateExcludeNullSnakeCase);
|
||||
_serilog = LoggerFactory.createLogger();
|
||||
//JsonSerializer.SetDefaultResolver(StandardResolver.AllowPrivateExcludeNullSnakeCase);
|
||||
Information("Geekbot", "Using GeekbotLogger");
|
||||
}
|
||||
|
||||
|
@ -36,7 +40,8 @@ namespace Geekbot.net.Lib
|
|||
private Task HandleLogObject(string type, string source, string message, Exception stackTrace = null, object extra = null)
|
||||
{
|
||||
var logJson = CreateLogObject(type, source, message, null, extra);
|
||||
Console.WriteLine(logJson);
|
||||
// fuck serilog
|
||||
_serilog.Information(logJson + "}");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
@ -51,7 +56,7 @@ namespace Geekbot.net.Lib
|
|||
StackTrace = stackTrace,
|
||||
Extra = extra
|
||||
};
|
||||
return Utf8Json.JsonSerializer.ToJsonString(logObject);
|
||||
return JsonSerializer.ToJsonString(logObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
using System;
|
||||
using Serilog;
|
||||
using System.Linq;
|
||||
using Serilog.Formatting.Json;
|
||||
using Serilog.Sinks.SumoLogic;
|
||||
|
||||
namespace Geekbot.net.Lib
|
||||
{
|
||||
public class LoggerFactory
|
||||
{
|
||||
public static ILogger createLogger(string[] args)
|
||||
public static ILogger createLogger()
|
||||
{
|
||||
var loggerCreation = new LoggerConfiguration()
|
||||
.WriteTo.RollingFile("Logs/geekbot-{Date}.txt", shared: true);
|
||||
if (!Environment.CurrentDirectory.Contains("deploy"))
|
||||
var loggerCreation = new LoggerConfiguration();
|
||||
var template = "{Message}{NewLine}";
|
||||
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GEEKBOT_SUMO")))
|
||||
{
|
||||
loggerCreation.WriteTo.LiterateConsole();
|
||||
}
|
||||
if (args.Contains("--verbose"))
|
||||
{
|
||||
loggerCreation.MinimumLevel.Verbose();
|
||||
Console.WriteLine("Logging Geekbot Logs to Sumologic");
|
||||
loggerCreation.WriteTo.SumoLogic(Environment.GetEnvironmentVariable("GEEKBOT_SUMO"),
|
||||
outputTemplate: template);
|
||||
}
|
||||
else
|
||||
{
|
||||
loggerCreation.MinimumLevel.Information();
|
||||
loggerCreation.WriteTo.LiterateConsole(outputTemplate: template);
|
||||
loggerCreation.WriteTo.RollingFile("Logs/geekbot-{Date}.txt", shared: true, outputTemplate: template);
|
||||
}
|
||||
return loggerCreation.CreateLogger();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue