static void Main() { ILogger logger = LoggerCreator.CreateLogger(a => a.AddConsole()); logger.Info("test"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(logger)); }
public void FileLogger_FileExistAtPath_True() { // Arrange string fileName = "logFile.txt"; var logger = LoggerCreator.CreateLogger(a => a.AddFileLog(fileName, LogDirectory, Configuration.LogEvent.Info)); // Act logger.Info("Testing."); // Assert Assert.IsTrue(File.Exists(Path.Combine(LogDirectory, fileName))); }
public void FileLogger_FileContainsSpecifiedText_True() { // Arrange string message = "Testing."; string fileName = "logFile.txt"; var logger = LoggerCreator.CreateLogger(a => a.AddFileLog(fileName, LogDirectory, Configuration.LogEvent.Info)); // Act logger.Info(message); // Assert string text = File.ReadAllText(Path.Combine(LogDirectory, fileName)); Assert.IsTrue(text.Contains(message)); }
public void FileLogger_InfoLogFileSpecifiedButDebugEventCalled_Throw() { // Arrange string debugMessage = "DebugMessage."; string fileName = "logFile.txt"; var logger = LoggerCreator.CreateLogger(a => a.AddFileLog(fileName, LogDirectory, Configuration.LogEvent.Info)); // Act logger.Info("Testing."); logger.Debug(debugMessage); // Assert string text = File.ReadAllText(Path.Combine(LogDirectory, fileName)); Assert.IsFalse(text.Contains(debugMessage)); }
public void FileLogger_SpecifiedFileForInfoLoggerAndFileForOtherEvents_OtherFileExist() { // Arrange string infoMessage = "InfoMessage."; string debugMessage = "DebugMessage."; string infoFileName = "infoLogFile.txt"; string otherFileName = "otherLogFile.txt"; var logger = LoggerCreator.CreateLogger(a => a.AddFileLog(infoFileName, LogDirectory, Configuration.LogEvent.Info) .AddFileLog(otherFileName, LogDirectory, Configuration.LogEvent.AllOther)); // Act logger.Info(infoMessage); logger.Debug(debugMessage); // Assert Assert.IsTrue(File.Exists(Path.Combine(LogDirectory, otherFileName))); }
internal FileProcessor(string inFile, string outLocation) { var inputIsCsv = Path.GetExtension(inFile).ToLower() == ".csv"; var outFileWithoutExtension = outLocation + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(inFile); var config = new OrchestratorConfig(LoggerCreator.CreateLogger(LoggerType.LogFile, "Unbound JSON translation to/from CSV.", LogEntrySeverity.Information)) { ReportProgress = true, ProgressInterval = 1000, ProgressChangedHandler = (s, e) => { if (e.Phase == Phase.Intake) { Console.Write($"\rProcessed {e.RecCnt:N0} records so far..."); } }, PhaseFinishedHandler = (s, e) => { if (e.Phase == Phase.Intake) { Console.WriteLine($"\rProcessed {e.RecCnt:N0} records. Done! "); } }, InputFileName = inFile }; if (inputIsCsv) // CSV to UnboundJSON { config.InputDataKind = KindOfTextData.Delimited; config.HeadersInFirstInputRow = true; config.AllowTransformToAlterFields = true; config.OutputDataKind = KindOfTextData.UnboundJSON; config.XmlJsonOutputSettings = "IndentChars| "; // pretty print config.OutputFileName = outFileWithoutExtension + ".json"; } else // UnboundJSON to CSV { config.InputDataKind = KindOfTextData.UnboundJSON; config.AllowOnTheFlyInputFields = true; // TODO: consider UnboundJSON ignoring this setting like X12 config.AllowTransformToAlterFields = true; //IMPORTANT! otherwise null items will be produced! config.OutputDataKind = KindOfTextData.Delimited; config.OutputFileName = outFileWithoutExtension + ".csv"; config.HeadersInFirstOutputRow = true; } Orchestrator = OrchestratorCreator.GetEtlOrchestrator(config); }
public void FileLogger_SpecifiedFileForInfoLoggerAndFileForOtherEvents_InfoFileContainsInfoMessage() { // Arrange string infoMessage = "InfoMessage."; string debugMessage = "DebugMessage."; string infoFileName = "infoLogFile.txt"; string otherFileName = "otherLogFile.txt"; var logger = LoggerCreator.CreateLogger(a => a.AddFileLog(infoFileName, LogDirectory, Configuration.LogEvent.Info) .AddFileLog(otherFileName, LogDirectory, Configuration.LogEvent.AllOther)); // Act logger.Info(infoMessage); logger.Debug(debugMessage); // Assert string text = File.ReadAllText(Path.Combine(LogDirectory, infoFileName)); Assert.IsTrue(text.Contains(infoMessage)); }
public void Ctor_SomeExplicitSettings_SettingsAccepted() { //arrange var config = new OrchestratorConfig(LoggerCreator.CreateLogger(LoggerType.LogFile, "Test", LogEntrySeverity.Error)); //act // note that this is not a sensible set of settings (!) config.ExplicitTypeDefinitions = "DOB|D,Amount|M,Name|S"; config.TypeDefiner = fn => new ItemDef(ItemType.Int, "000"); //everything int, except for 3 exceptions above config.MarkerStartsCluster = false; config.BufferSize = 7; config.InputDataKind = KindOfTextData.Arbitrary; config.AsyncIntake = true; config.RetainQuotes = true; config.ActionOnDuplicateKey = ActionOnDuplicateKey.AssignDefaultKey; config.DefaultInputFieldWidth = 6; config.TransformerType = TransformerType.ClusterFilter; config.ClusterFilterPredicate = c => false; config.RecordFilterPredicate = r => false; //makes no sense in the orchestrator, but good to test config.ConcurrencyLevel = 19; config.OutputDataKind = KindOfTextData.Flat; config.OutputFileNames = "blahblah"; config.QuotationMode = QuotationMode.StringsAndDates; config.TrimOutputValues = true; config.OutputKeyPrefix = "pfx_"; //assert //Logger: config.Logger.LoggerType.Should().Be(LoggerType.LogFile); config.Logger.LoggingThreshold.Should().Be(LogEntrySeverity.Error); // Environmental settings: config.ConfigName.Should().BeNull(); config.DataConveyerInfo.Should().BeOfType(typeof(ProductInfo)); config.DataConveyerInfo.Name.Should().Be("DataConveyer"); var ver = Assembly.GetAssembly(typeof(EtlOrchestrator)).GetName().Version; config.DataConveyerInfo.Version.Should().Be($"{ver.Major}.{ver.Minor}"); //General settings: config.ExplicitTypeDefinitions.Should().Be("DOB|D,Amount|M,Name|S"); config.TypeDefiner.Should().BeOfType(typeof(Func <string, ItemDef>)); config.TypeDefiner.Should().NotBe(OrchestratorConfig.DefaultTypeDefiner); config.TypeDefiner("anyKey").Type.Should().Be(ItemType.Int); config.EagerInitialization.Should().BeFalse(); config.BufferSize.Should().Be(7); config.ReportProgress.Should().BeFalse(); config.ProgressInterval.Should().Be(0); config.PhaseStartingHandler.Should().BeNull(); config.ProgressChangedHandler.Should().BeNull(); config.PhaseFinishedHandler.Should().BeNull(); //Intake specific settings: config.InputDataKind.Should().Be(KindOfTextData.Arbitrary); config.InputFileNames.Should().BeNull(); config.AsyncIntake.Should().BeTrue(); config.IntakeSupplier.Should().Be(OrchestratorConfig.DefaultIntakeSupplier); config.AsyncIntakeSupplier.Should().Be(OrchestratorConfig.DefaultAsyncIntakeSupplier); config.IntakeBufferFactor.Should().Be(1.5); config.HeadersInFirstInputRow.Should().BeFalse(); config.RetainQuotes.Should().BeTrue(); config.TrimInputValues.Should().BeFalse(); config.InputKeyPrefix.Should().BeNull(); config.ExcludeItemsMissingPrefix.Should().BeFalse(); config.ActionOnDuplicateKey.Should().Be(ActionOnDuplicateKey.AssignDefaultKey); config.ClusterMarker.Should().Be(OrchestratorConfig.DefaultClusterMarker); config.MarkerStartsCluster.Should().BeFalse(); config.InputFields.Should().BeNull(); config.ArbitraryInputDefs.Should().BeNull(); config.DefaultInputFieldWidth.Should().Be(6); config.AllowOnTheFlyInputFields.Should().BeFalse(); //Transformer specific settings: config.TransformerType.Should().Be(TransformerType.ClusterFilter); config.ClusterboundTransformer.Should().Be(OrchestratorConfig.DefaultClusterboundTransformer); config.RecordboundTransformer.Should().Be(OrchestratorConfig.DefaultRecordboundTransformer); config.ClusterFilterPredicate.Should().BeOfType(typeof(Func <ICluster, bool>)); config.ClusterFilterPredicate.Should().NotBe(OrchestratorConfig.DefaultClusterFilterPredicate); config.ClusterFilterPredicate(null).Should().BeFalse(); config.RecordFilterPredicate.Should().NotBe(OrchestratorConfig.DefaultRecordFilterPredicate); config.RecordFilterPredicate(null).Should().BeFalse(); // this predicate would never be called (due to TransformerType setting) config.UniversalTransformer.Should().Be(OrchestratorConfig.DefaultUniversalTransformer); config.ConcurrencyLevel.Should().Be(19); config.TransformBufferFactor.Should().Be(1); config.AllowTransformToAlterFields.Should().BeFalse(); //Output specific settings: config.OutputDataKind.Should().Be(KindOfTextData.Flat); config.OutputFileNames.Should().Be("blahblah"); config.AsyncOutput.Should().BeFalse(); config.OutputConsumer.Should().Be(OrchestratorConfig.DefaultOutputConsumer); config.AsyncOutputConsumer.Should().Be(OrchestratorConfig.DefaultAsyncOutputConsumer); config.OutputBufferFactor.Should().Be(1.5); config.HeadersInFirstOutputRow.Should().BeFalse(); config.QuotationMode.Should().Be(QuotationMode.StringsAndDates); config.TrimOutputValues.Should().BeTrue(); config.OutputKeyPrefix.Should().Be("pfx_"); config.OutputFields.Should().BeNull(); config.ArbitraryOutputDefs.Should().BeNull(); config.DefaultOutputFieldWidth.Should().Be(10); config.LeaderContents.Should().BeNull(); config.TrailerContents.Should().BeNull(); config.ExcludeExtraneousFields.Should().BeFalse(); }