Last active
March 19, 2020 06:24
-
-
Save dejanvasic85/a94c43441a9369c9120b02b5d011cc3c to your computer and use it in GitHub Desktop.
Logging Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IAppBuilder ConfigureSerilog(this IAppBuilder app, HttpConfiguration config) | |
{ | |
config.Services.Add(typeof(IExceptionLogger), new SerilogExceptionLogger()); | |
var assembly = typeof(SerilogConfig).Assembly.GetName(); | |
var configurationProvider = new ConfigurationProvider(AppSettingKey.Prefix); | |
var logEventLevel = configurationProvider.Get(AppSettingKey.SerilogLoggingLevel, LogEventLevel.Error); | |
const string logFileName = "talentsearch-api.json"; | |
var logFilePath = Path.Combine(configurationProvider.Get(AppSettingKey.SerilogFilePath), logFileName); | |
var serilog = new LoggerConfiguration() | |
.MinimumLevel.Debug() | |
.WriteTo.Sink(new RollingFileSink( | |
logFilePath, | |
textFormatter: new JsonFormatter(renderMessage: true), | |
fileSizeLimitBytes: 100000000, | |
retainedFileCountLimit: 14), logEventLevel) | |
.Enrich.WithMachineName() | |
.Enrich.With<StructuredExceptionEnricher>() | |
.Enrich.WithProperty("ApplicationName", assembly.Name) | |
.Enrich.WithProperty("ApplicationVersion", assembly.Version) | |
.Enrich.WithProperty("UserName", Environment.UserName) | |
.Enrich.WithProperty("AppDomain", AppDomain.CurrentDomain) | |
.Enrich.WithProperty("RuntimeVersion", Environment.Version) | |
// this ensures that calls to LogContext.PushProperty will cause the logger to be enriched | |
.Enrich.FromLogContext(); | |
if (Environment.UserInteractive || Environment.OSVersion.Platform == PlatformID.Unix) | |
{ | |
serilog = serilog.WriteTo.ColoredConsole(logEventLevel); | |
} | |
Log.Logger = serilog.CreateLogger(); | |
app.SetLoggerFactory(new Serilog.Extras.MSOwin.LoggerFactory(Log.Logger)); | |
app.UseSerilogRequestContext(); | |
Log.Debug("Owin_Startup"); | |
return app; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/var/log/containers/*-stdouterr.log { | |
size 10M | |
rotate 5 | |
missingok | |
compress | |
notifempty | |
copytruncate | |
dateext | |
dateformat %s | |
olddir /var/log/containers/rotated | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/var/log/containers/talentsearch-api/*.log { | |
size 1M | |
rotate 5 | |
missingok | |
compress | |
notifempty | |
copytruncate | |
dateext | |
dateformat %s | |
olddir /var/log/containers/talentsearch-api/rotated | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/var/log/containers/talentsearch-api/*.log { | |
size 1M | |
rotate 5 | |
missingok | |
compress | |
notifempty | |
copytruncate | |
dateext | |
dateformat %s | |
olddir /var/log/containers/talentsearch-api/rotated | |
} | |
[ec2-user@ip-172-25-147-139 logrotate.elasticbeanstalk.hourly]$ cat logrotate.elasticbeanstalk.docker.conf | |
/var/log/docker-events.log { | |
size 10M | |
rotate 5 | |
missingok | |
compress | |
notifempty | |
copytruncate | |
dateext | |
dateformat %s | |
olddir /var/log/rotated | |
} | |
/var/log/docker-ps.log { | |
size 10M | |
rotate 5 | |
missingok | |
compress | |
notifempty | |
copytruncate | |
dateext | |
dateformat %s | |
olddir /var/log/rotated | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment