public static TaskScheduler GetThreadLocalScheduler(IApplicationLogSettings config) { SetTaskSchedulerFactory(config); return(_threadStaticScheduler ?? (_threadStaticScheduler = CreateScheduler())); }
private static void SetTaskSchedulerFactory(IApplicationLogSettings config) { if (_isConfigSet) { return; } _isConfigSet = true; try { MaxDegreeOfParallelism = config.MaxThreads < 1 ? 50 : config.MaxThreads; } catch { MaxDegreeOfParallelism = 50; } UseWorkerProcessThreadPool = config.UseWorkerProcessThreads; _globalScheduler = CreateScheduler(); }
protected static void LoadConfiguration(IApplicationLogSettings settings) { try { if (settings == null) { throw new LogConfigurationException(LogResources.MissingConfiguration); } #region Custom Locator var providerType = settings.CustomLocatorAdapter; if (string.IsNullOrWhiteSpace(providerType)) { throw new LogConfigurationException(LogResources.Configuration_MissingCustomLocatorProvider); } var provider = GetServiceLocatorDelegate(providerType); LocatorProvider.SetLocator(provider); #endregion var taskFactory = TaskScheduling.Utility.GetTaskFactory(settings); var categories = new Dictionary <string, LoggerElementCollection>(); foreach (CategoryElement category in settings.Categories) { categories[category.Name] = category.Loggers; } if (!string.IsNullOrWhiteSpace(settings.CustomFormatter)) { var type = Type.GetType(settings.CustomFormatter); if (type == null) { throw new LogConfigurationException(LogResources.Configuration_CustomFormatter_NotFound); } var formatter = Activator.CreateInstance(type) as ILogEntryFormatter; if (formatter == null) { throw new LogConfigurationException(LogResources.Configuration_CustomFormatter_Invalid); } FormattingFactory.SetFormatter(formatter); } //Set Compression Provider Compression.ICompressionProvider compressionProvider; switch (settings.CompressionType) { case CompressionTypeOptions.Zip: compressionProvider = new Compression.GZipCompressionProvider(); break; case CompressionTypeOptions.Deflate: compressionProvider = new Compression.DeflateCompressionProvider(); break; case CompressionTypeOptions.Custom: if (string.IsNullOrWhiteSpace(settings.CustomCompressionType)) { throw new LogConfigurationException(LogResources.Configuration_CustomCompressionType_NotFound); } var type = Type.GetType(settings.CustomCompressionType); if (type == null) { throw new LogConfigurationException(LogResources.Configuration_CustomCompressionType_NotFound); } compressionProvider = Activator.CreateInstance(type) as Compression.ICompressionProvider; if (compressionProvider == null) { throw new LogConfigurationException(LogResources.Configuration_CustomCompressionType_Invalid); } break; default: throw new LogConfigurationException( string.Format(LogResources.CompressionType_NotSupported, Enum.GetName(typeof(CompressionTypeOptions), settings.CompressionType))); } Compression.CompressionProviderFactory.CurrentProvider = compressionProvider; LogSection = settings; Categories = categories; TaskFactory = taskFactory; FailSafeLogFactory.SetFailOverLoggingBehaviour(settings.ReThrowLogExceptions == SwitchOptions.On); } catch (LogConfigurationException) { throw; } catch (Exception ex) { throw new LogConfigurationException(LogResources.LogConfigurationError_Generic, ex); } }
public void RefreshSettings(IApplicationLogSettings settings) { LoadConfiguration(settings); }
public static TaskScheduler GetGlobalScheduler(IApplicationLogSettings config) { SetTaskSchedulerFactory(config); return(_globalScheduler); }