private void SetupLoggerly(ILoggerFactory loggerFactory, IHostApplicationLifetime appLifetime, IConfiguration config) { var logConfig = LogglyConfig.Instance; // Setup Basics logConfig.CustomerToken = config["Loggerly:Token"]; logConfig.ApplicationName = config["Loggerly:AppName"]; // Setup Host logConfig.Transport.EndpointHostname = config["Loggerly:EndpointHostname"]; logConfig.Transport.EndpointPort = 443; logConfig.Transport.LogTransport = LogTransport.Https; // Add Tag var ct = new ApplicationNameTag(); ct.Formatter = "application-{0}"; logConfig.TagConfig.Tags.Add(ct); // Setup Level to Log var logLevel = _env.IsProduction() ? LogEventLevel.Warning : LogEventLevel.Debug; // Setup Serilog Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Loggly(logLevel) .CreateLogger(); // Add Serilog loggerFactory.AddSerilog(); // Ensure that log is flushed appLifetime.ApplicationStopped.Register(Log.CloseAndFlush); }
private void ConfigureLogging(IHostingEnvironment env) { if (false)//env.IsDevelopment()) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning) .MinimumLevel.Override("System", Serilog.Events.LogEventLevel.Warning) .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); } else { var config = LogglyConfig.Instance; config.CustomerToken = "bd919fb8-1661-434c-bab3-4751fab77e9a"; config.ApplicationName = $"HealthCoach-{env.EnvironmentName}"; config.Transport.EndpointHostname = "logs-01.loggly.com"; config.Transport.EndpointPort = 443; config.Transport.LogTransport = LogTransport.Https; var ct = new ApplicationNameTag(); ct.Formatter = "application-{0}"; config.TagConfig.Tags.Add(ct); Log.Logger = new LoggerConfiguration() .MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning) .MinimumLevel.Override("System", Serilog.Events.LogEventLevel.Warning) .Enrich.FromLogContext() .WriteTo.Loggly(Serilog.Events.LogEventLevel.Information) .CreateLogger(); } }
private void StartLogging() { var config = LogglyConfig.Instance; config.CustomerToken = Configuration.GetValue <string>("LogglyToken"); config.ApplicationName = "ItHappenedWebApi"; config.Transport.EndpointHostname = "logs-01.loggly.com"; config.Transport.EndpointPort = 443; config.Transport.LogTransport = LogTransport.Https; var ct = new ApplicationNameTag(); ct.Formatter = "application-{0}"; config.TagConfig.Tags.Add(ct); var splunkConfiguration = Configuration.GetSection("Splunk"); var splunkUrl = splunkConfiguration["SplunkUrl"]; var splunkToken = splunkConfiguration["SplunkToken"]; Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Loggly() .WriteTo.EventCollector(splunkUrl, splunkToken) .WriteTo.RollingFile("log-{Date}.log") .CreateLogger(); Log.Information("Loggly started"); Log.Information("Splunk started"); }
public static ILogglyClient GetClient() { var config = LogglyConfig.Instance; config.CustomerToken = CustomerToken; config.ApplicationName = ApplicationName; config.Transport.EndpointHostname = "logs-01.loggly.com"; config.Transport.EndpointPort = 443; config.Transport.LogTransport = LogTransport.Https; var ct = new ApplicationNameTag(); ct.Formatter = "application-{0}"; config.TagConfig.Tags.Add(ct); return(new LogglyClient()); }
public static void ConfigureLoggly(this IServiceCollection services, IConfiguration configuration) { var logglyConfig = new LogglyConfiguration(); configuration.GetSection("Loggly").Bind(logglyConfig); var config = LogglyConfig.Instance; config.CustomerToken = logglyConfig.CustomerToken; config.ApplicationName = $"AspNetCoreNlogLogglyTutorial"; config.Transport.EndpointHostname = "logs-01.loggly.com"; config.Transport.EndpointPort = 443; config.Transport.LogTransport = LogTransport.Https; var ct = new ApplicationNameTag(); ct.Formatter = "AspNetCoreNlogLogglyTutorial"; config.TagConfig.Tags.Add(ct); }
public void LogglyClientSendException() { var config = LogglyConfig.Instance; config.CustomerToken = "83fe7674-f87d-473e-a8af-bbbbbbbbbbbb"; config.ApplicationName = $"test"; config.Transport.EndpointHostname = "logs-01.loggly.com"; config.Transport.EndpointPort = 443; config.Transport.LogTransport = LogTransport.Https; var ct = new ApplicationNameTag { Formatter = "application-{0}" }; config.TagConfig.Tags.Add(ct); var logglyClient = new LogglyClient(); try { ThrowException(); } catch (Exception e) { LogglyEvent logglyEvent = new LogglyEvent { Timestamp = DateTimeOffset.UtcNow, Syslog = { Level = Level.Emergency } }; logglyEvent.Data.AddIfAbsent("Message", "xZx"); logglyEvent.Data.AddIfAbsent("Level", "Error"); logglyEvent.Data.AddIfAbsent("Exception", e); var res = logglyClient.Log(logglyEvent).Result; Assert.Equal(ResponseCode.Success, res.Code); } Thread.Sleep(5000); }
private void StartLoggly() { var config = LogglyConfig.Instance; config.CustomerToken = Configuration.GetValue <string>("LogglyToken"); config.ApplicationName = "ItHappenedWebApi"; config.Transport.EndpointHostname = "logs-01.loggly.com"; config.Transport.EndpointPort = 443; config.Transport.LogTransport = LogTransport.Https; var ct = new ApplicationNameTag(); ct.Formatter = "application-{0}"; config.TagConfig.Tags.Add(ct); Log.Logger = new LoggerConfiguration() .MinimumLevel.Information() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Loggly() .CreateLogger(); Log.Information("Loggly started"); }
public Logger CreateLogger(string _environment, string _appName, string token) { var config = LogglyConfig.Instance; config.CustomerToken = token; config.ApplicationName = $"{_appName}-{_environment}"; config.Transport.EndpointHostname = "logs-01.loggly.com"; config.Transport.EndpointPort = 443; config.Transport.LogTransport = LogTransport.Https; var ct = new ApplicationNameTag(); ct.Formatter = $"{_appName}-{_environment}"; config.TagConfig.Tags.Add(ct); return(new LoggerConfiguration() .MinimumLevel.Verbose() .MinimumLevel.Override("System", LogEventLevel.Warning) .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .Enrich.FromLogContext() .WriteTo.Loggly(restrictedToMinimumLevel: LogEventLevel.Information) .CreateLogger()); }