Vedi README.md per le modifiche

This commit is contained in:
Gaetano Savo 2025-05-24 11:50:15 +02:00
parent 58390fb3bb
commit d6bbe2882d
8 changed files with 82 additions and 34 deletions

View File

@ -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_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_warning.ps1: Estrae i log degli warning dal log arm_build.log in arm_warning.log
- arm_build.md: Descrizione di arm_build.ps1 - 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

View File

@ -14,7 +14,7 @@
connectionStringName="SqlServerStampeC6Connection" connectionStringName="SqlServerStampeC6Connection"
commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite], commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
[Exception], [Application]) [Exception], [Application])
VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);"> VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);">
<parameter name="@application" layout="ContrattoSei" /> <parameter name="@application" layout="ContrattoSei" />
<parameter name="@machineName" layout="${machinename}" /> <parameter name="@machineName" layout="${machinename}" />
<parameter name="@logged" layout="${date}" /> <parameter name="@logged" layout="${date}" />

View File

@ -14,7 +14,7 @@
connectionStringName="SqlServerStampeC6Connection" connectionStringName="SqlServerStampeC6Connection"
commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite], commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
[Exception], [Application]) [Exception], [Application])
VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);"> VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);">
<parameter name="@application" layout="ContrattoSei" /> <parameter name="@application" layout="ContrattoSei" />
<parameter name="@machineName" layout="${machinename}" /> <parameter name="@machineName" layout="${machinename}" />
<parameter name="@logged" layout="${date}" /> <parameter name="@logged" layout="${date}" />

View File

@ -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" 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], commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
[Exception], [Application]) [Exception], [Application])
VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);"> VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);">
<parameter name="@application" layout="ContrattoSei" /> <parameter name="@application" layout="ContrattoSei" />
<parameter name="@machineName" layout="${machinename}" /> <parameter name="@machineName" layout="${machinename}" />
<parameter name="@logged" layout="${date}" /> <parameter name="@logged" layout="${date}" />

View File

@ -14,7 +14,7 @@
connectionStringName="SqlServerStampeC6Connection" connectionStringName="SqlServerStampeC6Connection"
commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite], commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
[Exception], [Application]) [Exception], [Application])
VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);"> VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);">
<parameter name="@application" layout="ContrattoSei" /> <parameter name="@application" layout="ContrattoSei" />
<parameter name="@machineName" layout="${machinename}" /> <parameter name="@machineName" layout="${machinename}" />
<parameter name="@logged" layout="${date}" /> <parameter name="@logged" layout="${date}" />

View File

@ -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" 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], commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
[Exception], [Application]) [Exception], [Application])
VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);"> VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);">
<parameter name="@application" layout="ContrattoSei" /> <parameter name="@application" layout="ContrattoSei" />
<parameter name="@machineName" layout="${machinename}" /> <parameter name="@machineName" layout="${machinename}" />
<parameter name="@logged" layout="${date}" /> <parameter name="@logged" layout="${date}" />

View File

@ -14,7 +14,7 @@
connectionStringName="SqlServerStampeC6Connection" connectionStringName="SqlServerStampeC6Connection"
commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite], commandText=" INSERT INTO [dbo].LogN ([Logged], [Level], [Message], [Logger], [CallSite],
[Exception], [Application]) [Exception], [Application])
VALUES (@logged, @level, @message, @logger, @callSite, @exception, @application);"> VALUES (GETDATE(), @level, @message, @logger, @callSite, @exception, @application);">
<parameter name="@application" layout="ContrattoSei" /> <parameter name="@application" layout="ContrattoSei" />
<parameter name="@machineName" layout="${machinename}" /> <parameter name="@machineName" layout="${machinename}" />
<parameter name="@logged" layout="${date}" /> <parameter name="@logged" layout="${date}" />

View File

@ -1,28 +1,51 @@
using System; using System;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Linq; using System.Linq;
using System.IO;
using System.Text; using System.Text;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration;
namespace DataAccessLayer namespace DataAccessLayer
{ {
public static class SqlLogging 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(); private static readonly object lockObj = new object();
static SqlLogging() 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<string, object> parameters = null, long executionTimeMs = 0) public static void LogStoredProcedure(string spName, Dictionary<string, object> parameters = null, long executionTimeMs = 0)
@ -30,7 +53,7 @@ namespace DataAccessLayer
try try
{ {
var logBuilder = new StringBuilder(); 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}"); logBuilder.AppendLine($"Name: {spName}");
if (parameters != null && parameters.Count > 0) 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)); WriteToLogN(
"Info",
lock (lockObj) logBuilder.ToString(),
{ "SqlLogging",
File.AppendAllText(GetLogFileName(), logBuilder.ToString()); $"LogStoredProcedure({spName})"
} );
} }
catch (Exception ex) catch (Exception ex)
{ {
System.Diagnostics.Debug.WriteLine($"Error logging stored procedure: {ex.Message}"); 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 try
{ {
var logBuilder = new StringBuilder(); var logBuilder = new StringBuilder();
logBuilder.AppendLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}]");
logBuilder.AppendLine($"Command Type: {command.CommandType}"); logBuilder.AppendLine($"Command Type: {command.CommandType}");
if (command.CommandType == System.Data.CommandType.StoredProcedure) 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)); WriteToLogN(
"Info",
lock (lockObj) logBuilder.ToString(),
{ "SqlLogging",
File.AppendAllText(GetLogFileName(), logBuilder.ToString()); $"LogCommand({command.CommandType})"
} );
} }
catch (Exception ex) catch (Exception ex)
{ {
System.Diagnostics.Debug.WriteLine($"Error logging SQL command: {ex.Message}"); System.Diagnostics.Debug.WriteLine($"Error logging SQL command: {ex.Message}");
WriteToLogN("Error", ex.Message, "SqlLogging", "LogCommand", ex.ToString());
} }
} }
} }