From 412e848e3cb73dee0f6f5228af5fe5f61d44a758 Mon Sep 17 00:00:00 2001 From: MatthiasSort Date: Thu, 1 Feb 2024 11:09:20 +0100 Subject: [PATCH] Added same msg into the Logger as there is sent to the LogManager plus uptimize the Writer so it is not calling GetColumnMappings everytime it writes. Bump version to 10.0.11 --- ...icweb.DataIntegration.Providers.SqlProvider.csproj | 2 +- src/SQLDestinationWriter.cs | 11 +++++++---- src/SQLProvider.cs | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Dynamicweb.DataIntegration.Providers.SqlProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.SqlProvider.csproj index 0a75dfe..969a283 100644 --- a/src/Dynamicweb.DataIntegration.Providers.SqlProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.SqlProvider.csproj @@ -1,6 +1,6 @@  - 10.0.10 + 10.0.11 1.0.0.0 SQL Provider SQL Provider diff --git a/src/SQLDestinationWriter.cs b/src/SQLDestinationWriter.cs index 868c4de..176abfb 100644 --- a/src/SQLDestinationWriter.cs +++ b/src/SQLDestinationWriter.cs @@ -43,6 +43,7 @@ public int RowsToWriteCount protected DuplicateRowsHandler duplicateRowsHandler; protected readonly bool removeMissingAfterImportDestinationTablesOnly; protected readonly bool SkipFailingRows; + private readonly ColumnMappingCollection _columnMappings; /// /// Initializes a new instance of the SqlDestinationWriter class. @@ -90,6 +91,7 @@ public SqlDestinationWriter(Mapping mapping, SqlConnection connection, bool remo public SqlDestinationWriter(Mapping mapping, SqlConnection connection, bool removeMissingAfterImport, ILogger logger, string tempTablePrefix, bool discardDuplicates) { Mapping = mapping; + _columnMappings = Mapping.GetColumnMappings(); SqlCommand = connection.CreateCommand(); SqlCommand.CommandTimeout = 1200; this.removeMissingAfterImport = removeMissingAfterImport; @@ -116,6 +118,7 @@ public SqlDestinationWriter(Mapping mapping, SqlConnection connection, bool remo public SqlDestinationWriter(Mapping mapping, SqlConnection connection, bool removeMissingAfterImport, ILogger logger, bool discardDuplicates) { Mapping = mapping; + _columnMappings = Mapping.GetColumnMappings(); SqlCommand = connection.CreateCommand(); SqlCommand.CommandTimeout = 1200; this.removeMissingAfterImport = removeMissingAfterImport; @@ -142,6 +145,7 @@ public SqlDestinationWriter(Mapping mapping, SqlConnection connection, bool remo public SqlDestinationWriter(Mapping mapping, SqlCommand mockSqlCommand, bool removeMissingAfterImport, ILogger logger, string tempTablePrefix, bool discardDuplicates) { Mapping = mapping; + _columnMappings = Mapping.GetColumnMappings(); SqlCommand = mockSqlCommand; this.removeMissingAfterImport = removeMissingAfterImport; this.logger = logger; @@ -153,14 +157,13 @@ public SqlDestinationWriter(Mapping mapping, SqlCommand mockSqlCommand, bool rem protected new virtual void Initialize() { List destColumns = new List(); - var columnMappings = Mapping.GetColumnMappings(); - foreach (ColumnMapping columnMapping in columnMappings.DistinctBy(obj => obj.DestinationColumn.Name)) + foreach (ColumnMapping columnMapping in _columnMappings.DistinctBy(obj => obj.DestinationColumn.Name)) { destColumns.Add((SqlColumn)columnMapping.DestinationColumn); } if (Mapping.DestinationTable != null && Mapping.DestinationTable.Name == "EcomAssortmentPermissions") { - if (columnMappings.Find(m => string.Compare(m.DestinationColumn.Name, "AssortmentPermissionAccessUserID", true) == 0) == null) + if (_columnMappings.Find(m => string.Compare(m.DestinationColumn.Name, "AssortmentPermissionAccessUserID", true) == 0) == null) destColumns.Add(new SqlColumn("AssortmentPermissionAccessUserID", typeof(string), SqlDbType.Int, null, -1, false, true, false)); } SQLTable.CreateTempTable(SqlCommand, Mapping.DestinationTable.SqlSchema, Mapping.DestinationTable.Name, tempTablePrefix, destColumns, logger); @@ -189,7 +192,7 @@ public SqlDestinationWriter(Mapping mapping, SqlCommand mockSqlCommand, bool rem DataRow dataRow = TableToWrite.NewRow(); - var columnMappings = Mapping.GetColumnMappings().Where(cm => cm.Active); + var columnMappings = _columnMappings.Where(cm => cm.Active); foreach (ColumnMapping columnMapping in columnMappings) { object rowValue = null; diff --git a/src/SQLProvider.cs b/src/SQLProvider.cs index f07bcdf..b024eda 100644 --- a/src/SQLProvider.cs +++ b/src/SQLProvider.cs @@ -519,7 +519,10 @@ public override bool RunJob(Job job) catch (Exception ex) { string msg = ex.Message; - LogManager.System.GetLogger(LogCategory.Application, "Dataintegration").Error($"{GetType().Name} error: {ex.Message} Stack: {ex.StackTrace}", ex); + string stackTrace = ex.StackTrace; + + Logger?.Error($"Error: {msg.Replace(System.Environment.NewLine, " ")} Stack: {stackTrace.Replace(System.Environment.NewLine, " ")}", ex); + LogManager.System.GetLogger(LogCategory.Application, "Dataintegration").Error($"{GetType().Name} error: {msg} Stack: {stackTrace}", ex); if (ex.Message.Contains("Subquery returned more than 1 value")) msg += System.Environment.NewLine + "This error usually indicates duplicates on column that is used as primary key or identity.";