Skip to content

Commit

Permalink
Merge pull request #28 from dynamicweb/mss/17238-ExtraLogging
Browse files Browse the repository at this point in the history
Added same msg into the Logger as there is sent to the LogManager plu…
  • Loading branch information
frederik5480 authored Feb 1, 2024
2 parents 38b6389 + 412e848 commit da6b66b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.10</Version>
<Version>10.0.11</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>SQL Provider</Title>
<Description>SQL Provider</Description>
Expand Down
11 changes: 7 additions & 4 deletions src/SQLDestinationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public int RowsToWriteCount
protected DuplicateRowsHandler duplicateRowsHandler;
protected readonly bool removeMissingAfterImportDestinationTablesOnly;
protected readonly bool SkipFailingRows;
private readonly ColumnMappingCollection _columnMappings;

/// <summary>
/// Initializes a new instance of the SqlDestinationWriter class.
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -153,14 +157,13 @@ public SqlDestinationWriter(Mapping mapping, SqlCommand mockSqlCommand, bool rem
protected new virtual void Initialize()
{
List<SqlColumn> destColumns = new List<SqlColumn>();
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);
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/SQLProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down

0 comments on commit da6b66b

Please sign in to comment.