public void CanUsePrivateConfiguration() { LoggingConfigurator.Configure("NoSuchFileHere"); LoggingConfigurator.UsePrivateConfiguration = true; // There must be at least one repo, our private one: var repos = LogManager.GetAllRepositories(); Assert.NotNull(repos); Assert.True(repos.Length > 0); const string repoName = "ProSuite.Commons"; var repo = LogManager.GetRepository(repoName); Assert.NotNull(repo, $"Could not find our private repo: {repoName}"); LoggingConfigurator.UsePrivateConfiguration = false; // Repo cannot be removed, but should have been shut down: Assert.NotNull(LogManager.GetRepository(repoName)); // While at it: GetRepository() throws if given unknown name: Assert.Catch(() => LogManager.GetRepository("NoSuchLogRepo")); }
private static void ConfigureLogging() { if (!AppConfigurationSettings.IsProductionEnvironment) { LoggingConfigurator.AddAppenderBuilder <ConsoleAppenderBuilder>(); } LoggingConfigurator.AddAppenderBuilder <FileAppenderBuilder>(); //LoggingConfigurator.AddAppenderBuilder<AdoNetAppenderBuilder>(); LoggingConfigurator.Configure(); }
public void CanConfigure() { const string fileName = "NoSuchFileHere"; var searchDirs = new string[0]; const bool useDefaultConfiguration = true; // Must not throw because a log config file is considered optional! LoggingConfigurator.Configure(fileName, searchDirs, useDefaultConfiguration); // Since we used the default config, logging must still be configured! Assert.True(LoggingConfigurator.IsConfigured()); }
// This method gets called by the runtime. Use this method to add services to the container public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddOptions(); services.AddLogging(loggingBuilder => { LoggingConfigurator.Configure(loggingBuilder, Configuration); }); ServicesConfiguration.Configure(services, Configuration); }
public static void Configure([NotNull] string configFileName, bool useDefaultConfiguration = true, bool dontOverwriteExistingConfiguration = false) { Assert.ArgumentNotNullOrEmpty(configFileName, nameof(configFileName)); var directorySearcher = new AppDirectorySearcher( ConfigurationUtils.CompanyName, ConfigurationUtils.ProductName, ConfigurationUtils.GetInstallDirectory().FullName); LoggingConfigurator.Configure(configFileName, directorySearcher.GetSearchPaths(), useDefaultConfiguration, dontOverwriteExistingConfiguration); }
public void ConfigureServices(IServiceCollection services) { services.AddSingleton <IConfiguration>(Configuration); services.AddOptions(); services.AddLogging(loggingBuilder => { //var loggingConfigSection = Configuration.GetSection(Configuration["Logging"]); //loggingBuilder.AddConfiguration(loggingConfigSection); //loggingBuilder.AddConsole(); loggingBuilder.AddProvider(new Logging.CollectorConsoleLoggingProvider()); loggingBuilder.AddDebug(); LoggingConfigurator.Configure(loggingBuilder, Configuration); }); ServicesConfiguration.Configure(services, Configuration); }
public static void ConfigureLogging(bool verboseRequired, [NotNull] string logConfigFileName) { int processId = Process.GetCurrentProcess().Id; LoggingConfigurator.SetGlobalProperty("LogFileSuffix", $"PID_{processId}"); LoggingConfigurator.Configure(logConfigFileName, GetLogConfigPaths(), useDefaultConfiguration: true); _msg.ReportMemoryConsumptionOnError = true; bool verboseLogging = verboseRequired || EnvironmentUtils.GetBooleanEnvironmentVariableValue(_verboseLoggingEnvVar); if (verboseLogging) { _msg.DebugFormat("Verbose logging configured by env var ({0})", _verboseLoggingEnvVar); _msg.IsVerboseDebugEnabled = true; } Assembly exeAssembly = Assert.NotNull(Assembly.GetEntryAssembly()); string bitness = Environment.Is64BitProcess ? "64 bit" : "32 bit"; _msg.InfoFormat("Logging configured for {0} ({1}) version {2}", exeAssembly.Location, bitness, exeAssembly.GetName().Version); if (_msg.IsVerboseDebugEnabled) { _msg.Debug("Environment variables:"); foreach (DictionaryEntry de in Environment.GetEnvironmentVariables()) { _msg.DebugFormat(" {0} = {1}", de.Key, de.Value); } } }
// This method gets called by the runtime. Use this method to add services to the container public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddOptions(); services.AddLogging(loggingBuilder => { LoggingConfigurator.Configure(loggingBuilder); }); var identityServerAuthenticationSettings = Configuration .GetSection("IdentityServerAuthenticationSettings") .Get <IdentityServerAuthenticationSettings>(); services .AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) .AddIdentityServerAuthentication(x => { x.Authority = identityServerAuthenticationSettings.Authority; x.ApiName = identityServerAuthenticationSettings.ApiName; x.ApiSecret = identityServerAuthenticationSettings.ApiSecret; x.RequireHttpsMetadata = false; }); services.AddAuthorization(options => { options.AddPolicy("UserAllowedDataCollection", policy => { policy.RequireAuthenticatedUser(); policy.Requirements.Add(new UserAllowedDataCollectionRequirement()); } ); }); services.AddSingleton <IAuthorizationHandler, UserAllowedDataCollectionHandler>(); ServicesConfiguration.Configure(services, Configuration); }
public static void ConfigureUnittestLogging() { List <string> logDirs = new List <string>(); string currentDir = Environment.CurrentDirectory; if (Directory.Exists(currentDir)) { logDirs.Add(currentDir); } string assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Assert.IsNotNull(assemblyDir); if (Directory.Exists(assemblyDir)) { logDirs.Add(assemblyDir); DirectoryInfo parent = Directory.GetParent(assemblyDir); if (parent?.Exists == true) { logDirs.Add(parent.FullName); } } if (!LoggingConfigurator.Configure(_loggingConfigurationFile, logDirs)) { Console.WriteLine("Logging configurator failed."); Console.WriteLine("logging configuration file: " + _loggingConfigurationFile); Console.WriteLine("Search directories: " + StringUtils.Concatenate(logDirs, ", ")); } else { Console.WriteLine("Logging configured."); } }
private static void ConfigureLogging() { LoggingConfigurator.AddAppenderBuilder <FileAppenderBuilder>(); LoggingConfigurator.Configure(); }