Exemplo n.º 1
0
        public static LoggerConfiguration ConfigueRollingFile(this LoggerSinkConfiguration configuration,
                                                              ITextFormatter formatter,
                                                              bool shared   = true,
                                                              bool buffered = false,
                                                              int retainedFileCountLimit             = 31,
                                                              int fileSizeLimitBytes                 = 1073741824,
                                                              LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
                                                              string path = null,
                                                              RollingInterval rollingInterval = RollingInterval.Day)
        {
            return(configuration.File(formatter,
                                      path ?? Path.Combine(
#if NETFULL
                                          AppDomain.CurrentDomain.BaseDirectory
#else
                                          AppContext.BaseDirectory
#endif
                                          , "logs", "log.log"),
                                      restrictedToMinimumLevel: restrictedToMinimumLevel,
                                      fileSizeLimitBytes: fileSizeLimitBytes,
                                      retainedFileCountLimit: retainedFileCountLimit,
                                      shared: shared,
                                      buffered: buffered,
                                      rollOnFileSizeLimit: true,
                                      rollingInterval: rollingInterval
                                      ));
        }
        private static void LogInitialization()
        {
            string applicationDataDirectory = @"DigitalZenWorks\MusicManager";
            string baseDataDirectory        = Environment.GetFolderPath(
                Environment.SpecialFolder.ApplicationData,
                Environment.SpecialFolderOption.Create) + @"\" +
                                              applicationDataDirectory;

            string       logFilePath    = baseDataDirectory + @"\MusicManager.log";
            const string outputTemplate =
                "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] " +
                "{Message:lj}{NewLine}{Exception}";

            LoggerConfiguration configuration = new ();

            configuration = configuration.MinimumLevel.Verbose();

            LoggerSinkConfiguration sinkConfiguration = configuration.WriteTo;

            sinkConfiguration.Console(LogEventLevel.Verbose, outputTemplate);
            sinkConfiguration.File(
                logFilePath,
                LogEventLevel.Verbose,
                outputTemplate,
                flushToDiskInterval: TimeSpan.FromSeconds(1));
            Serilog.Log.Logger = configuration.CreateLogger();

            LogManager.Adapter =
                new Common.Logging.Serilog.SerilogFactoryAdapter();
        }
Exemplo n.º 3
0
 private static LoggerConfiguration JsonFile(this LoggerSinkConfiguration configuration, string fileName)
 {
     return(configuration.File(new JsonFormatter(renderMessage: true),
                               Path.Combine(AppContext.BaseDirectory, $"logs//{fileName}.json"),
                               shared: true,
                               fileSizeLimitBytes: 20_971_520, // roughly 20 MB
                               rollOnFileSizeLimit: true,
                               retainedFileCountLimit: 10));
 }
Exemplo n.º 4
0
        public static LoggerConfiguration HostLevelLog(this LoggerSinkConfiguration writeTo)
        {
            var template = ConfigConsts.Logging.HostLevelLogTemplate;

#if DEBUG
            return(writeTo.Console(restrictedToMinimumLevel: LogEventLevel.Information, outputTemplate: template));
#else
            return(writeTo.File($"{ConfigConsts.Logging.HostLevelLogFolder}/{ConfigConsts.Logging.HostLevelLogFile}",
                                rollingInterval: RollingInterval.Month,
                                restrictedToMinimumLevel: LogEventLevel.Information, outputTemplate: template));
#endif
        }
        public static LoggerConfiguration RollingFile(this LoggerSinkConfiguration configuration, string logFileName)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            return(configuration.File(
                       new CompactJsonFormatter(),
                       logFileName,
                       buffered: false,
                       rollOnFileSizeLimit: true));
        }
Exemplo n.º 6
0
        private static void StartUp()
        {
            LoggerConfiguration     configuration     = new LoggerConfiguration();
            LoggerSinkConfiguration sinkConfiguration = configuration.WriteTo;

            sinkConfiguration.Console(LogEventLevel.Verbose, OutputTemplate);
            sinkConfiguration.File(
                LogFilePath, LogEventLevel.Verbose, OutputTemplate);
            Serilog.Log.Logger = configuration.CreateLogger();

            LogManager.Adapter =
                new Common.Logging.Serilog.SerilogFactoryAdapter();
        }
Exemplo n.º 7
0
        public static LoggerConfiguration HostLevelLog(this LoggerSinkConfiguration writeTo)
        {
            var template = LoggingConsts.HostLevelLogTemplate;
            var env      = Environment.GetEnvironmentVariable(EnvironmentVariables.AspNetCoreEnv.Key);

            if (env == EnvironmentVariables.AspNetCoreEnv.Development)
            {
                return(writeTo.Console(restrictedToMinimumLevel: LogEventLevel.Information, outputTemplate: template));
            }

            return(writeTo.File($"{LoggingConsts.HostLevelLogFolder}/{LoggingConsts.HostLevelLogFile}",
                                rollingInterval: RollingInterval.Month,
                                restrictedToMinimumLevel: LogEventLevel.Information, outputTemplate: template));
        }
        public static LoggerConfiguration RollingFile(this LoggerSinkConfiguration configuration, string logFileName,
                                                      ITextFormatter expressionTemplate, int retainedFileCountLimit = 31,
                                                      RollingInterval rollingInterval = RollingInterval.Day, int fileSizeLimitBytes = 1024 * 1024 * 1024)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            return(configuration.File(
                       expressionTemplate,
                       logFileName,
                       buffered: false,
                       rollOnFileSizeLimit: true,
                       rollingInterval: rollingInterval,
                       retainedFileCountLimit: retainedFileCountLimit,
                       fileSizeLimitBytes: fileSizeLimitBytes));
        }
Exemplo n.º 9
0
 public void RegisterSink(LoggerSinkConfiguration sinkConfiguration)
 {
     sinkConfiguration.File(new ElasticsearchJsonFormatter(), _options.FilePath, rollingInterval: _options.RollingInterval, fileSizeLimitBytes: _options.FileSizeLimitBytes,
                            retainedFileCountLimit: _options.RetainedFileCountLimit, rollOnFileSizeLimit: _options.RollOnFileSizeLimit);
 }
 public static LoggerConfiguration AzureWebAppDiagnostics(this LoggerSinkConfiguration config) =>
 config.File(
     @"D:\home\LogFiles\Application\log.txt",
     fileSizeLimitBytes: 1_000_000,