public void VerifyAllConfigOptionsMappedToConfigObject() { var pipelineConfigObj = new Dictionary <string, object> { ["inputs"] = new List <Dictionary <string, object> > { new Dictionary <string, object> { ["logLevel"] = "Verbose" } } }; using (var configFile = new TemporaryFile()) { var pipelineConfig = JsonConvert.SerializeObject(pipelineConfigObj, EventFlowJsonUtilities.DefaultSerializerSettings); configFile.Write(pipelineConfig); var configBuilder = new ConfigurationBuilder(); configBuilder.AddJsonFile(configFile.FilePath); var configuration = configBuilder.Build(); var inputsConfigSection = configuration.GetSection("inputs"); var configFragments = inputsConfigSection.GetChildren().ToList(); var l4nInputConfiguration = new Log4netConfiguration(); configFragments[0].Bind(l4nInputConfiguration); Assert.Equal("Verbose", l4nInputConfiguration.LogLevel); } }
public Log4netInput(Log4netConfiguration log4NetConfigs, IHealthReporter healthReporter) { Requires.NotNull(log4NetConfigs, nameof(log4NetConfigs)); Requires.NotNull(healthReporter, nameof(healthReporter)); Initialize(log4NetConfigs, healthReporter); }
private void Initialize(Log4netConfiguration myLog4NetConfig, IHealthReporter myHealthReporter) { this.healthReporter = myHealthReporter; this._log4NetInputConfiguration = myLog4NetConfig; this.subject = new EventFlowSubject <EventData>(); //Can we determine if the repo exists without try/catch try { eventFlowRepo = (Hierarchy)LogManager.CreateRepository("EventFlowRepo"); _log4NetInputConfiguration.Log4netLevel = eventFlowRepo.LevelMap[_log4NetInputConfiguration.LogLevel]; BasicConfigurator.Configure(eventFlowRepo, this); } catch (LogException) { eventFlowRepo = (Hierarchy)LogManager.GetRepository("EventFlowRepo"); } }
public Log4netInput(IConfiguration configuration, IHealthReporter healthReporter) { Requires.NotNull(healthReporter, nameof(healthReporter)); Requires.NotNull(configuration, nameof(configuration)); var log4NetInputConfiguration = new Log4netConfiguration(); try { configuration.Bind(log4NetInputConfiguration); } catch { healthReporter.ReportProblem($"Invalid {nameof(log4NetInputConfiguration)} configuration encountered: '{configuration}'", EventFlowContextIdentifiers.Configuration); throw; } Initialize(log4NetInputConfiguration, healthReporter); }
public static void Register(IKernel kernel) { // Log4netConfiguration.Setup(@"D:\Logs\MihaylovWeb\log.txt"); // var loggerPath = HostingEnvironment.MapPath("~/App_Data/Log/log.txt"); kernel.Bind <ICustomSettingsManager>().To <CustomSettingsManager>().InSingletonScope(); var customSettingsManager = kernel.Get <ICustomSettingsManager>(); var loggerPath = customSettingsManager.Settings.LoggerPath; var connectionString = customSettingsManager.GetSettingByName("MihaylovDb"); var siteUrl = customSettingsManager.GetSettingByName("SiteUrl"); Log4netConfiguration.Setup(loggerPath); //var dataStoreFolder = HostingEnvironment.MapPath("~/App_Data/Google"); //kernel.Bind<IGoogleDriveApiHelper>().To<GoogleDriveApiHelper>().InSingletonScope() // .WithConstructorArgument("dataStoreFolder", dataStoreFolder); kernel.Load(new INinjectModule[] { new NinjectModuleCore(connectionString, siteUrl) }); kernel.Bind <IToastrHelper>().To <ToastrHelper>(); }
public void LowerLevelDefinedDoesNotWriteToPipeline() { var healthReportMock = new Mock <IHealthReporter>(); var configurationMock = new Log4netConfiguration { Log4netLevel = Level.Info }; var mockOutput = new Mock <IOutput>(); using (var log4NetInput = new Log4netInput(configurationMock, healthReportMock.Object)) using (var pipeline = new DiagnosticPipeline( healthReportMock.Object, new[] { log4NetInput }, new IFilter[0], new[] { new EventSink(mockOutput.Object, new IFilter[0]) })) { var logger = LogManager.GetLogger("EventFlowRepo", typeof(Log4NetInputTests)); logger.Debug("some message"); } mockOutput.Verify( output => output.SendEventsAsync(It.IsAny <IReadOnlyCollection <EventData> >(), It.IsAny <long>(), It.IsAny <CancellationToken>()), Times.Never); }
public void ValidConfigurationCanWrtieToInputPipleine() { var healthReportMock = new Mock <IHealthReporter>(); var configurationMock = new Log4netConfiguration { LogLevel = "INFO" }; var mockOutput = new Mock <IOutput>(); using (var log4NetInput = new Log4netInput(configurationMock, healthReportMock.Object)) using (var pipeline = new DiagnosticPipeline( healthReportMock.Object, new[] { log4NetInput }, new IFilter[0], new[] { new EventSink(mockOutput.Object, new IFilter[0]) })) { var logger = LogManager.GetLogger("EventFlowRepo", typeof(Log4NetInputTests)); logger.Info("some message"); } mockOutput.Verify( output => output.SendEventsAsync(It.Is <IReadOnlyCollection <EventData> >(c => c.Count == 1), It.IsAny <long>(), It.IsAny <CancellationToken>()), Times.Exactly(1)); }