Exemple #1
0
        protected static void GlobalSetup()
        {
            ShouldlyConfiguration.DefaultTaskTimeout = TimeSpan.FromMinutes(1);

            (String, String, String)dockerCredentials = ("https://www.docker.com", "stuartferguson", "Sc0tland");

            // Setup a network for the DB Server
            Setup.DatabaseServerNetwork = DockerHelper.SetupTestNetwork("sharednetwork");

            NlogLogger logger = new NlogLogger();

            logger.Initialise(LogManager.GetLogger("Specflow"), "Specflow");
            LogManager.AddHiddenAssembly(typeof(NlogLogger).Assembly);

            String sqlServerImageName           = "mcr.microsoft.com/mssql/server:2019-latest";
            DockerEnginePlatform enginePlatform = DockerHelper.GetDockerEnginePlatform();

            if (enginePlatform == DockerEnginePlatform.Windows)
            {
                sqlServerImageName = "tobiasfenster/mssql-server-dev-unsupported:2019-cu13";
            }

            // Start the Database Server here
            Setup.DatabaseServerContainer = Setup.StartSqlContainerWithOpenConnection(Setup.SqlServerContainerName,
                                                                                      logger,
                                                                                      sqlServerImageName,
                                                                                      Setup.DatabaseServerNetwork,
                                                                                      dockerCredentials,
                                                                                      Setup.SqlUserName,
                                                                                      Setup.SqlPassword);
        }
Exemple #2
0
 /// <summary>Apply NLog Gelf configuration from XML config.</summary>
 /// <param name="env"></param>
 /// <param name="configFileRelativePath">relative path to NLog configuration file.</param>
 /// <returns>LoggingConfiguration for chaining</returns>
 public static LoggingConfiguration ConfigureNLog(this IHostingEnvironment env, string configFileRelativePath)
 {
     ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(GelfConfigurationExtensions).GetTypeInfo().Assembly);
     LogManager.AddHiddenAssembly(typeof(GelfConfigurationExtensions).GetTypeInfo().Assembly);
     LogManager.LoadConfiguration(Path.Combine(env.ContentRootPath, configFileRelativePath));
     return(LogManager.Configuration);
 }
        /// <summary>
        /// Enable NLog as logging provider in ASP.NET Core.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="options">NLog options</param>
        /// <returns></returns>
        public static ILoggerFactory AddNLog(this ILoggerFactory factory, NLogProviderOptions options)
        {
            //ignore this
            LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging")));
            LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Abstractions")));

            try
            {
                //try the Filter ext
                var filterAssembly = Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Filter"));
                LogManager.AddHiddenAssembly(filterAssembly);
            }
            catch (Exception)
            {
                //ignore
            }

            LogManager.AddHiddenAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);

            using (var provider = new NLogLoggerProvider(options))
            {
                factory.AddProvider(provider);
            }
            return(factory);
        }
        /// <summary>
        /// Use NLog for Dependency Injected loggers.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="options">Options for logging to NLog with Dependency Injected loggers</param>
        /// <returns></returns>
        public static IWebHostBuilder UseNLog(this IWebHostBuilder builder, NLogAspNetCoreOptions options)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            options = options ?? NLogAspNetCoreOptions.Default;

            builder.ConfigureServices(services =>
            {
                ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);
                LogManager.AddHiddenAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);

                //note: when registering ILoggerFactory, all non NLog stuff and stuff before this will be removed
                services.AddSingleton <ILoggerProvider>(serviceProvider =>
                {
                    ServiceLocator.ServiceProvider = serviceProvider;
                    return(new NLogLoggerProvider(options));
                });

                //note: this one is called before  services.AddSingleton<ILoggerFactory>
                if (options.RegisterHttpContextAccessor)
                {
                    services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
                }
            });
            return(builder);
        }
Exemple #5
0
        private static void ConfigureServicesNLog(NLogAspNetCoreOptions options, IServiceCollection services, Func <IServiceProvider, IConfiguration> lookupConfiguration)
        {
            ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);
            LogManager.AddHiddenAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);

            services.AddSingleton <ILoggerProvider>(serviceProvider =>
            {
                ServiceLocator.ServiceProvider = serviceProvider;

                var provider      = new NLogLoggerProvider(options ?? new NLogProviderOptions());
                var configuration = lookupConfiguration(serviceProvider);
                if (configuration != null)
                {
                    ConfigSettingLayoutRenderer.DefaultConfiguration = configuration;
                    if (options == null)
                    {
                        provider.Configure(configuration.GetSection("Logging:NLog"));
                    }
                }

                return(provider);
            });

            //note: this one is called before  services.AddSingleton<ILoggerFactory>
            if ((options ?? NLogAspNetCoreOptions.Default).RegisterHttpContextAccessor)
            {
                services.AddHttpContextAccessor();
            }
        }
Exemple #6
0
        /// <summary>
        /// Enable NLog as logging provider for Harry.Logging.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="fullFilePath"></param>
        /// <returns></returns>
        public static ILoggerFactory AddNLog(
#if !NET20
            this
#endif
            ILoggerFactory factory, string fullFilePath = null)
        {
#if !NET20
            //ignore this
            LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Harry.Logging")));

#if !NET20 && !NET35 && !NET40
            LogManager.AddHiddenAssembly(typeof(NLogLoggerFactoryExtensions).GetTypeInfo().Assembly);
#else
            LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Harry.Logging.NLog")));
#endif
#endif

            if (!string.IsNullOrEmpty(fullFilePath))
            {
                LogManager.Configuration = new XmlLoggingConfiguration(fullFilePath, true);
            }

            using (var provider = new NLogLoggerProvider())
            {
                factory.AddProvider(provider);
            }
            return(factory);
        }
Exemple #7
0
        private static void ConfigureHiddenAssemblies()
        {
            try
            {
                //ignore these assemblies for ${callsite}
                LogManager.AddHiddenAssembly(typeof(Microsoft.Extensions.Logging.LoggerFactoryExtensions).GetTypeInfo().Assembly); //Microsoft.Extensions.Logging
                LogManager.AddHiddenAssembly(typeof(Microsoft.Extensions.Logging.ILogger).GetTypeInfo().Assembly);                 // Microsoft.Extensions.Logging.Abstractions
                LogManager.AddHiddenAssembly(typeof(NLog.Extensions.Logging.ConfigureExtensions).GetTypeInfo().Assembly);          //NLog.Extensions.Logging

                try
                {
                    //try the Filter ext
                    var filterAssembly = Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Filter"));
                    LogManager.AddHiddenAssembly(filterAssembly);
                }
                catch (Exception ex)
                {
                    InternalLogger.Trace(ex, "filtering Microsoft.Extensions.Logging.Filter failed. Not an issue probably");
                }
            }
            catch (Exception ex)
            {
                InternalLogger.Debug(ex, "failure in ignoring assemblies. This could influence the ${callsite}");
            }
        }
        /// <summary>
        /// Ignore assemblies for ${callsite}
        /// </summary>
        private static void RegisterHiddenAssembliesForCallSite()
        {
            InternalLogger.Debug("Hide assemblies for callsite");
            LogManager.AddHiddenAssembly(typeof(NLogLoggerProvider).GetTypeInfo().Assembly);
            Config.ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(NLogLoggerProvider).GetTypeInfo().Assembly);

#if !NETCORE1_0
            var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
            foreach (var assembly in allAssemblies)
            {
                if (assembly.FullName.StartsWith("NLog.Extensions.Logging,", StringComparison.OrdinalIgnoreCase) ||
                    assembly.FullName.StartsWith("NLog.Web,", StringComparison.OrdinalIgnoreCase) ||
                    assembly.FullName.StartsWith("NLog.Web.AspNetCore,", StringComparison.OrdinalIgnoreCase) ||
                    assembly.FullName.StartsWith("Microsoft.Extensions.Logging,", StringComparison.OrdinalIgnoreCase) ||
                    assembly.FullName.StartsWith("Microsoft.Extensions.Logging.Abstractions,", StringComparison.OrdinalIgnoreCase) ||
                    assembly.FullName.StartsWith("Microsoft.Extensions.Logging.Filter,", StringComparison.OrdinalIgnoreCase) ||
                    assembly.FullName.StartsWith("Microsoft.Logging,", StringComparison.OrdinalIgnoreCase))
                {
                    LogManager.AddHiddenAssembly(assembly);
                }
            }
#else
            SafeAddHiddenAssembly("Microsoft.Logging");
            SafeAddHiddenAssembly("Microsoft.Extensions.Logging");
            SafeAddHiddenAssembly("Microsoft.Extensions.Logging.Abstractions");

            //try the Filter ext, this one is not mandatory so could fail
            SafeAddHiddenAssembly("Microsoft.Extensions.Logging.Filter", false);
#endif
        }
Exemple #9
0
		static void ConfigTraditionalLog()
		{
			//workaround for log callsite bug (see https://github.com/NLog/NLog.Extensions.Logging/issues/165)
			LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging")));
			LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Abstractions")));
			LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("NLog.Extensions.Logging")));
		}
Exemple #10
0
 static void ConfigTraditionalLog()
 {
     //LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Filter")));
     LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging")));
     //LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Abstractions")));
     LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("NLog.Extensions.Logging")));
 }
        private static void AddNLogLoggerProvider(IServiceCollection services, IConfiguration configuration, NLogAspNetCoreOptions options, Func <IServiceProvider, IConfiguration, NLogAspNetCoreOptions, NLogLoggerProvider> factory)
        {
            ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);
            LogManager.AddHiddenAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);

            var sharedFactory = factory;

            if ((options ?? NLogAspNetCoreOptions.Default).ReplaceLoggerFactory)
            {
                NLogLoggerProvider singleInstance = null;   // Ensure that registration of ILoggerFactory and ILoggerProvider shares the same single instance
                sharedFactory = (provider, cfg, opt) => singleInstance ?? (singleInstance = factory(provider, cfg, opt));

                services.AddLogging(builder => builder?.ClearProviders());  // Cleanup the existing LoggerFactory, before replacing it with NLogLoggerFactory
                services.Replace(ServiceDescriptor.Singleton <ILoggerFactory, NLogLoggerFactory>(serviceProvider => new NLogLoggerFactory(sharedFactory(serviceProvider, configuration, options))));
            }

            services.TryAddEnumerable(ServiceDescriptor.Singleton <ILoggerProvider, NLogLoggerProvider>(serviceProvider => sharedFactory(serviceProvider, configuration, options)));

            if ((options ?? NLogAspNetCoreOptions.Default).RemoveLoggerFactoryFilter)
            {
                // Will forward all messages to NLog if not specifically overridden by user
                services.AddLogging(builder => builder?.AddFilter <NLogLoggerProvider>(null, Microsoft.Extensions.Logging.LogLevel.Trace));
            }

            //note: this one is called before  services.AddSingleton<ILoggerFactory>
            if ((options ?? NLogAspNetCoreOptions.Default).RegisterHttpContextAccessor)
            {
                services.AddHttpContextAccessor();
            }
        }
 /// <summary>
 /// Override the default <see cref="IServiceProvider" /> used by the NLog ServiceLocator.
 /// NLog ServiceLocator uses the <see cref="IServiceProvider" /> to access context specific services (Ex. <see cref="Microsoft.AspNetCore.Http.IHttpContextAccessor" />)
 /// </summary>
 /// <remarks>
 /// Should only be used if the standard approach for configuring NLog is not enough
 /// </remarks>
 /// <param name="serviceProvider"></param>
 public static IServiceProvider SetupNLogServiceLocator(this IServiceProvider serviceProvider)
 {
     ServiceLocator.ServiceProvider = serviceProvider;
     ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);
     LogManager.AddHiddenAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);
     return(serviceProvider);
 }
        private static void AnnotateFactories(IAnnotator annotator)
        {
            annotator.Annotate <LogManager>(type =>
            {
                type.Annotate(_ => LogManager.CreateNullLogger() == NotNull <ILogger>());
                type.Annotate(_ => LogManager.GetCurrentClassLogger() == NotNull <ILogger>());
                type.Annotate(_ => LogManager.GetCurrentClassLogger(CanBeNull <Type>()) == NotNull <ILogger>());
                type.Annotate(_ => LogManager.GetLogger(NotNull <string>()) == NotNull <ILogger>());
                type.Annotate(_ => LogManager.GetLogger(NotNull <string>(), CanBeNull <Type>()) == NotNull <ILogger>());
                type.Annotate(_ => LogManager.DefaultCultureInfo == NotNull <LogManager.GetCultureInfo>());
                type.Annotate(_ => LogManager.Configuration == CanBeNull <LoggingConfiguration>());
                type.Annotate(_ => LogManager.DisableLogging() == NotNull <IDisposable>());
                type.Annotate(_ => LogManager.AddHiddenAssembly(NotNull <Assembly>()));
                type.Annotate(_ => LogManager.Flush(NotNull <AsyncContinuation>()));
                type.Annotate(_ => LogManager.Flush(NotNull <AsyncContinuation>(), Some <TimeSpan>()));
                type.Annotate(_ => LogManager.Flush(NotNull <AsyncContinuation>(), Some <int>()));
            });

            annotator.Annotate <LogFactory>(type =>
            {
                type.Annotate(x => x.CreateNullLogger() == NotNull <ILogger>());
                type.Annotate(x => x.GetCurrentClassLogger() == NotNull <ILogger>());
                type.Annotate(x => x.GetCurrentClassLogger(CanBeNull <Type>()) == NotNull <ILogger>());
                type.Annotate(x => x.GetLogger(NotNull <string>()) == NotNull <ILogger>());
                type.Annotate(x => x.GetLogger(NotNull <string>(), CanBeNull <Type>()) == NotNull <ILogger>());
                type.Annotate(x => x.DefaultCultureInfo == CanBeNull <CultureInfo>());
                type.Annotate(x => x.Configuration == CanBeNull <LoggingConfiguration>());
                type.Annotate(x => x.DisableLogging() == NotNull <IDisposable>());
                type.Annotate(x => x.SuspendLogging() == NotNull <IDisposable>());
                type.Annotate(x => x.Flush(NotNull <AsyncContinuation>()));
                type.Annotate(x => x.Flush(NotNull <AsyncContinuation>(), Some <TimeSpan>()));
                type.Annotate(x => x.Flush(NotNull <AsyncContinuation>(), Some <int>()));
            });
        }
        /// <summary>
        /// Enable NLog as logging provider in Foundatio.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="populateAdditionalLogEventInfo">Callback that allows populating additional log event information from the log state and scopes.</param>
        /// <returns></returns>
        public static ILoggerFactory AddNLog(this ILoggerFactory factory, Action <object, object[], LogEventInfo> populateAdditionalLogEventInfo)
        {
            //ignore this
            LogManager.AddHiddenAssembly(typeof(LogFactoryExtensions).GetTypeInfo().Assembly);

            factory.AddProvider(new NLogLoggerProvider(populateAdditionalLogEventInfo));

            return(factory);
        }
        /// <summary>
        /// Enable NLog as logging provider in Foundatio.
        /// </summary>
        /// <param name="factory"></param>
        /// <returns></returns>
        public static ILoggerFactory AddNLog(this ILoggerFactory factory)
        {
            //ignore this
            LogManager.AddHiddenAssembly(typeof(LogFactoryExtensions).GetTypeInfo().Assembly);

            factory.AddProvider(new NLogLoggerProvider());

            return(factory);
        }
Exemple #16
0
 private static void SetupNlogConfig(ConsoleLoggerOptions options)
 {
     LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging")));
     LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Abstractions")));
     LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("NLog.Extensions.Logging")));
     LogManager.AddHiddenAssembly(typeof(ConsoleLoggerConfigureExtensions).GetTypeInfo().Assembly);
     LogManager.Configuration = new NlogConfigurationFactory().Create(options);
     LogManager.Configuration.Reload();
     LogManager.ReconfigExistingLoggers();
 }
Exemple #17
0
        public static ILoggerFactory AddNLog(this ILoggerFactory factory)
        {
            LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging")));
            LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Abstractions")));
            LogManager.AddHiddenAssembly(typeof(ConfigureExtensions).GetTypeInfo().Assembly);
            LogManager.AddHiddenAssembly(typeof(LoggerFactoryExtensions).GetTypeInfo().Assembly);

            factory.AddProvider(new NLogLoggerProvider());
            return(factory);
        }
Exemple #18
0
        public async Task StartSystem()
        {
            String     scenarioName = this.ScenarioContext.ScenarioInfo.Title.Replace(" ", "");
            NlogLogger logger       = new NlogLogger();

            logger.Initialise(LogManager.GetLogger(scenarioName), scenarioName);
            LogManager.AddHiddenAssembly(typeof(NlogLogger).Assembly);

            this.TestingContext.DockerHelper = new DockerHelper(logger);
            await this.TestingContext.DockerHelper.StartContainersForScenarioRun(scenarioName).ConfigureAwait(false);
        }
Exemple #19
0
        private static void ConfigureHiddenAssemblies()
        {
            //ignore this
            SafeAddHiddenAssembly("Microsoft.Extensions.Logging");
            SafeAddHiddenAssembly("Microsoft.Extensions.Logging.Abstractions");

            //try the Filter ext, this one is not mandatory so could fail
            SafeAddHiddenAssembly("Microsoft.Extensions.Logging.Filter", false);

            LogManager.AddHiddenAssembly(typeof(ConfigureExtensions).GetTypeInfo().Assembly);
        }
Exemple #20
0
        /// <summary>
        /// Enable NLog as logging provider in ASP.NET Core.
        /// </summary>
        /// <param name="factory"></param>
        /// <returns></returns>
        public static ILoggerFactory AddNLog(this ILoggerFactory factory)
        {
            //ignore this
            LogManager.AddHiddenAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);

            using (var provider = new NLogLoggerProvider())
            {
                factory.AddProvider(provider);
            }
            return(factory);
        }
Exemple #21
0
 /// <summary>
 /// 添加NLog日志记录器
 /// </summary>
 /// <param name="factory">日志工厂</param>
 /// <param name="fileName">配置文件名称</param>
 public static ILoggerFactory AddNLog(this ILoggerFactory factory, string fileName = InternalConst.DefaultConfigFile)
 {
     if (!string.IsNullOrEmpty(fileName) && File.Exists(fileName))
     {
         LogManager.Configuration = new XmlLoggingConfiguration(fileName, true);
     }
     LogManager.AddHiddenAssembly(typeof(NLogLoggerFactoryExtensions).GetTypeInfo().Assembly);
     using (var provider = new NLogLoggerProvider())
         factory.AddProvider(provider);
     return(factory);
 }
Exemple #22
0
        /// <summary>
        /// Enable NLog as logging provider in ASP.NET Core.
        /// </summary>
        /// <param name="factory"></param>
        /// <returns></returns>
        public static ILoggerFactory AddNLog(this ILoggerFactory factory)
        {
            //ignore this
            LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging")));
            LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Abstractions")));
            LogManager.AddHiddenAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);

            using (var provider = new NLogLoggerProvider())
            {
                factory.AddProvider(provider);
            }
            return(factory);
        }
Exemple #23
0
        private static void AddNLogLoggerProvider(IServiceCollection services, IConfiguration configuration, NLogAspNetCoreOptions options, Func <IServiceProvider, IConfiguration, NLogAspNetCoreOptions, NLogLoggerProvider> factory)
        {
            ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);
            LogManager.AddHiddenAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);

            services.TryAddEnumerable(ServiceDescriptor.Singleton <ILoggerProvider, NLogLoggerProvider>(serviceProvider => factory(serviceProvider, configuration, options)));

            //note: this one is called before  services.AddSingleton<ILoggerFactory>
            if ((options ?? NLogAspNetCoreOptions.Default).RegisterHttpContextAccessor)
            {
                services.AddHttpContextAccessor();
            }
        }
Exemple #24
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            if (_appSettingsOptions.Value.UseSameAssemblyLogger)
            {
                services.Replace(new ServiceDescriptor(typeof(ILogger <>), typeof(Logger <>), ServiceLifetime.Singleton));
            }

            if (_appSettingsOptions.Value.UseSeparateAssemblyLogger)
            {
                services.Replace(new ServiceDescriptor(typeof(ILogger <>), typeof(Logger.Logger <>), ServiceLifetime.Singleton));
                LogManager.AddHiddenAssembly(typeof(Logger.Logger <>).Assembly);
            }
        }
        /// <summary>Use NLog Target Gelf for Dependency Injected loggers.</summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IWebHostBuilder UseNLogTargetGelf(this IWebHostBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.ConfigureServices(services =>
            {
                ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(GelfConfigurationExtensions).GetTypeInfo().Assembly);
                LogManager.AddHiddenAssembly(typeof(GelfConfigurationExtensions).GetTypeInfo().Assembly);
            });

            return(builder);
        }
Exemple #26
0
 private static void SafeAddHiddenAssembly(string assemblyName, bool logOnException = true)
 {
     try
     {
         InternalLogger.Trace("Hide {0}", assemblyName);
         var assembly = Assembly.Load(new AssemblyName(assemblyName));
         LogManager.AddHiddenAssembly(assembly);
     }
     catch (Exception ex)
     {
         if (logOnException)
         {
             InternalLogger.Debug(ex, "Hiding assembly {0} failed. This could influence the ${callsite}", assemblyName);
         }
     }
 }
        public async Task StartSystem()
        {
            // Initialise a logger
            String     scenarioName = this.ScenarioContext.ScenarioInfo.Title.Replace(" ", "");
            NlogLogger logger       = new NlogLogger();

            logger.Initialise(LogManager.GetLogger(scenarioName), scenarioName);
            LogManager.AddHiddenAssembly(typeof(NlogLogger).Assembly);

            this.TestingContext.DockerHelper = new DockerHelper(logger, this.TestingContext);
            this.TestingContext.Logger       = logger;
            this.TestingContext.Logger.LogInformation("About to Start Containers for Scenario Run");
            await this.TestingContext.DockerHelper.StartContainersForScenarioRun(scenarioName).ConfigureAwait(false);

            this.TestingContext.Logger.LogInformation("Containers for Scenario Run Started");

            Thread.Sleep(20000);
        }
        /// <summary>
        /// Configures the <see cref="ILoggerFactory"/> to use the AXOOM logging configuration.
        /// </summary>
        /// <param name="loggerFactory">The logger factory to configure.</param>
        /// <param name="loggingOptions">The logging configuration.</param>
        public static ILoggerFactory UseAxoomLogging(this ILoggerFactory loggerFactory, LoggingOptions loggingOptions)
        {
            LayoutRenderer.Register <SysLogLevelLayoutRenderer>("sysloglevel");
            LayoutRenderer.Register <UnixTimeLayoutRenderer>("unixtime");

            loggerFactory
            .WithFilter(new FilterLoggerSettings {
                Switches = loggingOptions.Filter
            })
            .AddNLog();

            LogManager.AddHiddenAssembly(typeof(LoggerFactoryExtensions).GetTypeInfo().Assembly);
            LogManager.Configuration = NlogConfigurationFactory.Create(loggingOptions);
            LogManager.Configuration.Reload();
            LogManager.ReconfigExistingLoggers();

            return(loggerFactory);
        }
        /// <summary>
        /// Ignore assemblies for ${callsite}
        /// </summary>
        private static void RegisterHiddenAssembliesForCallSite()
        {
            InternalLogger.Debug("Hide assemblies for callsite");
            Config.ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(NLogLoggerProvider).GetTypeInfo().Assembly);

            LogManager.AddHiddenAssembly(typeof(NLogLoggerProvider).GetTypeInfo().Assembly);
            LogManager.AddHiddenAssembly(typeof(Microsoft.Extensions.Logging.ILogger).GetTypeInfo().Assembly);

#if !NETCORE1_0
            LogManager.AddHiddenAssembly(typeof(Microsoft.Extensions.Logging.LoggerFactory).GetTypeInfo().Assembly);
#else
            SafeAddHiddenAssembly("Microsoft.Logging");
            SafeAddHiddenAssembly("Microsoft.Extensions.Logging");

            //try the Filter ext, this one is not mandatory so could fail
            SafeAddHiddenAssembly("Microsoft.Extensions.Logging.Filter", false);
#endif
        }
Exemple #30
0
        private static void ConfigureHiddenAssemblies()
        {
            //ignore this
            LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging")));
            LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Abstractions")));

            try
            {
                //try the Filter ext
                var filterAssembly = Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Filter"));
                LogManager.AddHiddenAssembly(filterAssembly);
            }
            catch (Exception)
            {
                //ignore
            }

            LogManager.AddHiddenAssembly(typeof(ConfigureExtensions).GetTypeInfo().Assembly);
        }