diff --git a/README.md b/README.md
index e5039b8..07015c6 100644
--- a/README.md
+++ b/README.md
@@ -6,3 +6,33 @@ Nel folder root\Powershell\ ci sono i file:
- arm_error.ps1: Estrae i log degli errori dal log arm_build.log in arm_error.log
- arm_warning.ps1: Estrae i log degli warning dal log arm_build.log in arm_warning.log
- arm_build.md: Descrizione di arm_build.ps1
+
+Ho modificato dei file App.config con
+ key="FTP" value="0" a key="FTP" value="false"
+ key="usePrefilledTables" value="1" a key="usePrefilledTables" value="true"
+ key="usePrefilledTables" ridividi value="0" a key="usePrefilledTables" value="false"
+
+## Problemi trovati
+
+### Insert in dbo.LogN
+
+Fa il log dei messaggi di Debug, Errore, .. nella tabella dbo.LogN con la insert
+ INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
+ [Exception], [Application])
+ VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);
+la colonna Logged รจ un datetime e il valore @logged arriva con un formato non valido (yyyy/mm/dd hh:mm:ss.mil).
+Modificata con:
+ INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
+ [Exception], [Application])
+ VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);
+
+### Procedure non esistenti
+
+#### C6MartPeriodico.GESTIONE_SELECT_PDF_GETDATATHREADS_CRUSCOTTO_TEST
+
+Usa la procedura C6MartPeriodico.GESTIONE_SELECT_PDF_GETDATATHREADS_CRUSCOTTO_TEST che non esiste ne esistono svariate con nome C6MartPeriodico.GESTIONE_SELECT_PDF_GETDATATHREADS_CRUSCOTTO e C6MartPeriodico.GESTIONE_SELECT_PDF_GETDATATHREADS_CRUSCOTTO_nn
+Creata come copia di GESTIONE_SELECT_PDF_GETDATATHREADS_CRUSCOTTO
+
+### Spostato log sql e stored lanciati su tabella dbo.LogN
+
+I log sql e stored lanciati sono stati spostati su tabella dbo.LogN
\ No newline at end of file
diff --git a/root/Batch/DTSXRunner/ConsoleApplication2/nlog.config b/root/Batch/DTSXRunner/ConsoleApplication2/nlog.config
index eccf133..3dbb1eb 100644
--- a/root/Batch/DTSXRunner/ConsoleApplication2/nlog.config
+++ b/root/Batch/DTSXRunner/ConsoleApplication2/nlog.config
@@ -14,7 +14,7 @@
connectionStringName="SqlServerStampeC6Connection"
commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
[Exception], [Application])
- VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);">
+ VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);">
diff --git a/root/ContrattoSEI/EnforceIDXApp/NLog.config b/root/ContrattoSEI/EnforceIDXApp/NLog.config
index cbba227..86068d5 100644
--- a/root/ContrattoSEI/EnforceIDXApp/NLog.config
+++ b/root/ContrattoSEI/EnforceIDXApp/NLog.config
@@ -14,7 +14,7 @@
connectionStringName="SqlServerStampeC6Connection"
commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
[Exception], [Application])
- VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);">
+ VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);">
diff --git a/root/ContrattoSEI/GestorePDF/NLog.config b/root/ContrattoSEI/GestorePDF/NLog.config
index 48cfb9a..22a12d3 100644
--- a/root/ContrattoSEI/GestorePDF/NLog.config
+++ b/root/ContrattoSEI/GestorePDF/NLog.config
@@ -14,7 +14,7 @@
connectionString="Data Source=GSAVO-SURFACE-7; Database=C6StampeCentralizzate_testing;User Id=F701264; Password=contrsei; Max Pool Size=1000;Pooling=yes;Load Balance Timeout=1000; Connection Timeout=200"
commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
[Exception], [Application])
- VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);">
+ VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);">
diff --git a/root/ContrattoSEI/GestoreTrimestrale.Test/NLog.config b/root/ContrattoSEI/GestoreTrimestrale.Test/NLog.config
index fc4bcbd..a661563 100644
--- a/root/ContrattoSEI/GestoreTrimestrale.Test/NLog.config
+++ b/root/ContrattoSEI/GestoreTrimestrale.Test/NLog.config
@@ -14,7 +14,7 @@
connectionStringName="SqlServerStampeC6Connection"
commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
[Exception], [Application])
- VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);">
+ VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);">
diff --git a/root/ContrattoSEI/GestoreTrimestrale/NLog.config b/root/ContrattoSEI/GestoreTrimestrale/NLog.config
index f0bab28..3e272c0 100644
--- a/root/ContrattoSEI/GestoreTrimestrale/NLog.config
+++ b/root/ContrattoSEI/GestoreTrimestrale/NLog.config
@@ -14,7 +14,7 @@
connectionString="Data Source=GSAVO-SURFACE-7; Database=C6StampeCentralizzate;User Id=F701264; Password=contrsei; Max Pool Size=1000;Pooling=yes;Load Balance Timeout=1000; Connection Timeout=200"
commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
[Exception], [Application])
- VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);">
+ VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);">
diff --git a/root/ContrattoSEI/GestoreTrimestrale_branch_applyingMVVM/NLog.config b/root/ContrattoSEI/GestoreTrimestrale_branch_applyingMVVM/NLog.config
index c43798c..8c6a8fb 100644
--- a/root/ContrattoSEI/GestoreTrimestrale_branch_applyingMVVM/NLog.config
+++ b/root/ContrattoSEI/GestoreTrimestrale_branch_applyingMVVM/NLog.config
@@ -14,7 +14,7 @@
connectionStringName="SqlServerStampeC6Connection"
commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
[Exception], [Application])
- VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);">
+ VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);">
diff --git a/root/Shared/DataAccessLayer/SqlLogging.cs b/root/Shared/DataAccessLayer/SqlLogging.cs
index 0f3c4ef..70049ae 100644
--- a/root/Shared/DataAccessLayer/SqlLogging.cs
+++ b/root/Shared/DataAccessLayer/SqlLogging.cs
@@ -1,28 +1,51 @@
using System;
using System.Data.SqlClient;
using System.Linq;
-using System.IO;
using System.Text;
using System.Collections.Generic;
+using System.Configuration;
namespace DataAccessLayer
{
public static class SqlLogging
{
- private static readonly string LogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SqlLogs");
+ private static readonly string ConnectionString;
private static readonly object lockObj = new object();
static SqlLogging()
{
- if (!Directory.Exists(LogPath))
+ ConnectionString = ConfigurationManager.ConnectionStrings["SqlServerStampeC6Connection"]?.ConnectionString;
+ if (string.IsNullOrEmpty(ConnectionString))
{
- Directory.CreateDirectory(LogPath);
+ throw new ConfigurationErrorsException("SqlServerStampeC6Connection connection string not found in configuration.");
}
}
- private static string GetLogFileName()
+ private static void WriteToLogN(string level, string message, string logger, string callSite, string exception = null)
{
- return Path.Combine(LogPath, $"sql_log_{DateTime.Now:yyyyMMdd}.txt");
+ try
+ {
+ using (var conn = new SqlConnection(ConnectionString))
+ using (var cmd = conn.CreateCommand())
+ {
+ conn.Open();
+ cmd.CommandText = @"INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite], [Exception], [Application])
+ VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application)";
+
+ cmd.Parameters.AddWithValue("@level", level);
+ cmd.Parameters.AddWithValue("@message", message);
+ cmd.Parameters.AddWithValue("@logger", logger);
+ cmd.Parameters.AddWithValue("@callSite", callSite);
+ cmd.Parameters.AddWithValue("@exception", (object)exception ?? DBNull.Value);
+ cmd.Parameters.AddWithValue("@application", "SqlLogging");
+
+ cmd.ExecuteNonQuery();
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"Error writing to LogN: {ex.Message}");
+ }
}
public static void LogStoredProcedure(string spName, Dictionary parameters = null, long executionTimeMs = 0)
@@ -30,7 +53,7 @@ namespace DataAccessLayer
try
{
var logBuilder = new StringBuilder();
- logBuilder.AppendLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] STORED PROCEDURE");
+ logBuilder.AppendLine($"STORED PROCEDURE");
logBuilder.AppendLine($"Name: {spName}");
if (parameters != null && parameters.Count > 0)
@@ -43,21 +66,19 @@ namespace DataAccessLayer
}
}
- if (executionTimeMs > 0)
- {
- logBuilder.AppendLine($"Execution Time: {executionTimeMs}ms");
- }
+ logBuilder.AppendLine($"Execution Time: {executionTimeMs}ms");
- logBuilder.AppendLine(new string('-', 80));
-
- lock (lockObj)
- {
- File.AppendAllText(GetLogFileName(), logBuilder.ToString());
- }
+ WriteToLogN(
+ "Info",
+ logBuilder.ToString(),
+ "SqlLogging",
+ $"LogStoredProcedure({spName})"
+ );
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Error logging stored procedure: {ex.Message}");
+ WriteToLogN("Error", ex.Message, "SqlLogging", "LogStoredProcedure", ex.ToString());
}
}
@@ -66,7 +87,6 @@ namespace DataAccessLayer
try
{
var logBuilder = new StringBuilder();
- logBuilder.AppendLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}]");
logBuilder.AppendLine($"Command Type: {command.CommandType}");
if (command.CommandType == System.Data.CommandType.StoredProcedure)
@@ -88,21 +108,19 @@ namespace DataAccessLayer
}
}
- if (executionTimeMs > 0)
- {
- logBuilder.AppendLine($"Execution Time: {executionTimeMs}ms");
- }
+ logBuilder.AppendLine($"Execution Time: {executionTimeMs}ms");
- logBuilder.AppendLine(new string('-', 80));
-
- lock (lockObj)
- {
- File.AppendAllText(GetLogFileName(), logBuilder.ToString());
- }
+ WriteToLogN(
+ "Info",
+ logBuilder.ToString(),
+ "SqlLogging",
+ $"LogCommand({command.CommandType})"
+ );
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Error logging SQL command: {ex.Message}");
+ WriteToLogN("Error", ex.Message, "SqlLogging", "LogCommand", ex.ToString());
}
}
}