Пример #1
0
        public static Logger Create(
            string appName,
            ConfigurationServiceBase sharedConfig,
            LoggerConfigPredicate configPredicate = null)
        {
            if (Svc.Logger != null)
            {
                throw new NotSupportedException();
            }

            var config      = LoadConfig(sharedConfig);
            var levelSwitch = new LoggingLevelSwitch(config.LogLevel);

            var loggerConfig = new LoggerConfiguration()
                               .MinimumLevel.ControlledBy(levelSwitch)
                               .Enrich.WithExceptionDetails()
                               .Enrich.WithDemystifiedStackTraces()
                               .WriteTo.Debug(outputTemplate: OutputFormat)
                               .WriteTo.Async(
                a =>
                a.RollingFile(
                    GetLogFilePath(appName).FullPath,
                    fileSizeLimitBytes: 5242880,            // Math.Max(ConfigMgr.AppConfig.LogMaxSize, 5242880),
                    retainedFileCountLimit: 7,
                    shared: false,
                    outputTemplate: OutputFormat
                    ));

            //.WriteTo.File(
            //  GetLogFilePath(appName).FullPath,
            //  outputTemplate: OutputFormat);
            //.WriteTo.RollingFile(
            //  GetLogFilePath(appName).FullPath,
            //  fileSizeLimitBytes: 5242880,
            //  retainedFileCountLimit: 7,
            //  shared: false,
            //  outputTemplate: OutputFormat
            //);

            if (configPredicate != null)
            {
                loggerConfig = configPredicate(loggerConfig);
            }

            Log.Logger = loggerConfig.CreateLogger();

            return(new Logger(config, levelSwitch));
        }
        public static Logger Create(
            string appName,
            ConfigurationServiceBase sharedConfig,
            LoggerConfigPredicate configPredicate = null)
        {
            if (Svc.Logger != null)
            {
                throw new NotSupportedException();
            }

            var config      = LoadConfig(sharedConfig);
            var levelSwitch = new LoggingLevelSwitch(config.LogLevel);

            Log.Logger = CreateSerilog(appName, config, levelSwitch, configPredicate);

            return(new Logger(config, levelSwitch));
        }
Пример #3
0
        public static ILogger CreateSerilog(
            string appName,
            LoggerCfg loggerCfg                   = null,
            LoggingLevelSwitch levelSwitch        = null,
            LoggerConfigPredicate configPredicate = null)
        {
            var loggerConfig = new LoggerConfiguration()
                               .Enrich.WithExceptionDetails()
                               .Enrich.WithDemystifiedStackTraces()
                               .WriteTo.Debug(outputTemplate: OutputFormat)
                               .WriteTo.Async(
                a =>
                a.RollingFile(
                    GetLogFilePath(appName).FullPath,
                    fileSizeLimitBytes: Math.Max(loggerCfg?.LogMaxSize ?? 5242880, 10485760),
                    retainedFileCountLimit: 7,
                    shared: true,
                    outputTemplate: OutputFormat
                    ));

            //.WriteTo.File(
            //  GetLogFilePath(appName).FullPath,
            //  outputTemplate: OutputFormat);
            //.WriteTo.RollingFile(
            //  GetLogFilePath(appName).FullPath,
            //  fileSizeLimitBytes: 5242880,
            //  retainedFileCountLimit: 7,
            //  shared: false,
            //  outputTemplate: OutputFormat
            //);

            if (levelSwitch != null)
            {
                loggerConfig = loggerConfig.MinimumLevel.ControlledBy(levelSwitch);
            }

            if (configPredicate != null)
            {
                loggerConfig = configPredicate(loggerConfig);
            }

            return(loggerConfig.CreateLogger());
        }
Пример #4
0
        public void Initialize(
            string appName,
            LoggerConfigPredicate configPredicate = null)
        {
            _config     = LoadConfig();
            LevelSwitch = new LoggingLevelSwitch(_config.LogLevel);

            var config = new LoggerConfiguration()
                         .MinimumLevel.ControlledBy(LevelSwitch)
                         .Enrich.WithExceptionDetails()
                         .Enrich.WithDemystifiedStackTraces()
                         .WriteTo.Debug(outputTemplate: OutputFormat)
                         //.WriteTo.RollingFile(
                         //  GetLogFilePath(appName).FullPath,
                         //  fileSizeLimitBytes: 5242880,
                         //  retainedFileCountLimit: 7,
                         //  shared: false,
                         //  outputTemplate: OutputFormat
                         //);
                         .WriteTo.Async(
                a =>
                a.RollingFile(
                    GetLogFilePath(appName).FullPath,
                    fileSizeLimitBytes: 5242880,      // Math.Max(ConfigMgr.AppConfig.LogMaxSize, 5242880),
                    retainedFileCountLimit: 7,
                    shared: false,
                    outputTemplate: OutputFormat
                    ));

            if (configPredicate != null)
            {
                config = configPredicate(config);
            }

            Log.Logger = config.CreateLogger();

            LogTo.Debug("Logger initialized");

            RegisterExceptionLoggers();
        }