public HotKeyManager Initialize(ConfigurationServiceBase cfgSvc, IKeyboardHookService kbHookSvc) { _cfgSvc = cfgSvc; _kbHookSvc = kbHookSvc; if (_cfgSvc == null) { throw new InvalidOperationException($"_cfgSvc cannot be null during {nameof(HotKeyManager)} initialization"); } if (_config != null) { throw new InvalidOperationException($"{nameof(HotKeyManager)} is already initialized"); } _config = _cfgSvc.Load <HotKeyCfg>().Result ?? new HotKeyCfg(); foreach (var kvp in _config.HotKeyMap) { if (_userHotKeyMap.Reverse.ContainsKey(kvp.Value) == false) { _userHotKeyMap[kvp.Key] = kvp.Value; } } return(this); }
public static LoggerCfg LoadConfig(ConfigurationServiceBase sharedConfig) { try { return(sharedConfig.Load <LoggerCfg>().Result ?? new LoggerCfg()); } catch (Exception ex) { LogTo.Error(ex, "Exception while loading logger config"); return(new LoggerCfg()); } }
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)); }
public void ReloadConfig(ConfigurationServiceBase sharedCfg) { var newConfig = LoggerFactory.LoadConfig(sharedCfg); SetMinimumLevel(newConfig.LogLevel); if (newConfig.LogFirstChanceExceptions != Config.LogFirstChanceExceptions) { if (newConfig.LogFirstChanceExceptions) { RegisterFirstChanceExceptionLogger(); } else { UnregisterFirstChanceExceptionLogger(); } } Config = newConfig; }
internal async Task ReloadConfigFromFile(ConfigurationServiceBase cfgService) { Config = await cfgService.Load <LoggerCfg>(); ReloadConfig(); }