Reshape logging (disruptive) --> major update!!!

This commit is contained in:
Samuele E. Locatelli
2020-10-02 23:15:08 +02:00
parent a52ae045b7
commit e7ce86abf2
6 changed files with 242 additions and 233 deletions
Vendored
+3 -3
View File
@@ -8,9 +8,9 @@ pipeline {
/* calcolo numero versione... diverso x branch MASTER/DEVELOP */
script {
withEnv(['NEXT_BUILD_NUMBER=743']) {
// env.versionNumber = VersionNumber(versionNumberString : '4.9.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true)
env.versionNumber = VersionNumber(versionNumberString : '4.9.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}')
env.versionNumberBeta = VersionNumber(versionNumberString : '4.9.${BUILD_DATE_FORMATTED, "yyMM"}-beta.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}')
// env.versionNumber = VersionNumber(versionNumberString : '5.0.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true)
env.versionNumber = VersionNumber(versionNumberString : '5.0.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}')
env.versionNumberBeta = VersionNumber(versionNumberString : '5.0.${BUILD_DATE_FORMATTED, "yyMM"}-beta.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}')
env.APP_NAME = 'SteamWareLib'
}
}
+13 -8
View File
@@ -6,14 +6,19 @@ using System.Threading.Tasks;
namespace SteamWare.Logger
{
public class Constants
{
public enum ERROR_LEVEL
public class Constants
{
INFO = 1,
WARNING = 2,
ERROR = 3,
FATAL = 4
#region Public Enums
public enum ERROR_LEVEL
{
Info = 1,
Warning,
Error,
Exception,
Fatal
}
#endregion Public Enums
}
}
}
+87 -67
View File
@@ -6,92 +6,112 @@ using static SteamWare.Logger.Constants;
namespace SteamWare.Logger
{
/// <summary>
/// Classe helper x LOG basata su NLog
/// </summary>
public static class Logging
{
/// <summary>
/// S
/// Classe helper x LOG basata su NLog
/// </summary>
public static NLog.Logger Instance { get; private set; }
static Logging()
public static class Logging
{
#region Private Fields
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
#region Public Constructors
static Logging()
{
#if DEBUG
// Setup the logging view for Sentinel - http://sentinel.codeplex.com
var sentinalTarget = new NLogViewerTarget()
{
Name = "sentinal",
Address = "udp://127.0.0.1:9999",
IncludeNLogData = false
};
var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget);
LogManager.Configuration.AddTarget("sentinal", sentinalTarget);
LogManager.Configuration.LoggingRules.Add(sentinalRule);
// Setup the logging view for Sentinel - http://sentinel.codeplex.com
var sentinalTarget = new NLogViewerTarget()
{
Name = "sentinal",
Address = "udp://127.0.0.1:9999",
IncludeNLogData = false
};
var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget);
LogManager.Configuration.AddTarget("sentinal", sentinalTarget);
LogManager.Configuration.LoggingRules.Add(sentinalRule);
#endif
LogManager.ReconfigExistingLoggers();
LogManager.ReconfigExistingLoggers();
Instance = LogManager.GetCurrentClassLogger();
}
Instance = LogManager.GetCurrentClassLogger();
}
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
#endregion Public Constructors
public static void LogException(Exception ex, ERROR_LEVEL errorLevel)
{
LogMessage(ex.Message, errorLevel);
}
public static void LogMessage(string message, ERROR_LEVEL errorLevel)
{
switch (errorLevel)
{
case ERROR_LEVEL.INFO:
{
Log.Info(message);
}
break;
case ERROR_LEVEL.WARNING:
{
Log.Warn(message);
}
break;
#region Public Properties
case ERROR_LEVEL.ERROR:
{
/// <summary>
/// S
/// </summary>
public static NLog.Logger Instance { get; private set; }
#endregion Public Properties
#region Public Methods
public static void LogError(string message)
{
Log.Error(message);
}
break;
}
case ERROR_LEVEL.FATAL:
{
public static void LogException(Exception ex, ERROR_LEVEL errorLevel)
{
LogMessage(ex.Message, errorLevel);
}
public static void LogFatal(string message)
{
Log.Fatal(message);
}
break;
}
}
}
public static void LogInfo(string message)
{
Log.Info(message);
}
public static void LogInfo(string message)
{
Log.Info(message);
}
public static void LogWarning(string message)
{
Log.Warn(message);
}
public static void LogMessage(string message, ERROR_LEVEL errorLevel)
{
switch (errorLevel)
{
case ERROR_LEVEL.Info:
{
Log.Info(message);
}
break;
public static void LogError(string message)
{
Log.Error(message);
}
case ERROR_LEVEL.Warning:
{
Log.Warn(message);
}
break;
public static void LogFatal(string message)
{
Log.Fatal(message);
case ERROR_LEVEL.Error:
{
Log.Error(message);
}
break;
case ERROR_LEVEL.Fatal:
{
Log.Fatal(message);
}
break;
}
}
public static void LogWarning(string message)
{
Log.Warn(message);
}
#endregion Public Methods
}
}
}
-37
View File
@@ -1,37 +0,0 @@
using NLog;
using NLog.Config;
using NLog.Targets;
namespace SteamWare
{
/// <summary>
/// Classe helper x LOG basata su NLog
/// </summary>
public static class Log
{
/// <summary>
/// S
/// </summary>
public static Logger Instance { get; private set; }
static Log()
{
#if DEBUG
// Setup the logging view for Sentinel - http://sentinel.codeplex.com
var sentinalTarget = new NLogViewerTarget()
{
Name = "sentinal",
Address = "udp://127.0.0.1:9999",
IncludeNLogData = false
};
var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget);
LogManager.Configuration.AddTarget("sentinal", sentinalTarget);
LogManager.Configuration.LoggingRules.Add(sentinalRule);
#endif
LogManager.ReconfigExistingLoggers();
Instance = LogManager.GetCurrentClassLogger();
}
}
}
+6 -1
View File
@@ -269,7 +269,6 @@
<Compile Include="licenseMan.cs" />
<Compile Include="log2note.cs" />
<Compile Include="logger.cs" />
<Compile Include="Logging.cs" />
<Compile Include="memLayer.cs" />
<Compile Include="NetworkConnection.cs" />
<Compile Include="pdfUtils.cs" />
@@ -448,6 +447,12 @@
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SteamWare.Logger\SteamWare.Logger.csproj">
<Project>{97a9f482-c173-4f0f-9f8f-7bb41c59cdd6}</Project>
<Name>SteamWare.Logger</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+133 -117
View File
@@ -24,6 +24,8 @@ namespace SteamWare
#endregion oggetti protected utilizzati
#region Public Fields
/// <summary>
/// oggetto singleton x accesso al layer di memoria
/// </summary>
@@ -39,6 +41,12 @@ namespace SteamWare
/// </summary>
public DS_UtilityTableAdapters.ConfigTmpTableAdapter taConfigTmp;
#endregion Public Fields
#region Protected Constructors
/// <summary>
/// classe gestione accessi a Session, cache, viewstate, configuration...
/// </summary>
@@ -52,16 +60,11 @@ namespace SteamWare
setupMongo();
}
/// <summary>
/// Verifica se si debba serializzare ogni valore complesso (tabelle/righe) in sessione (per impiego di sessioni avanzate come Redis)
/// </summary>
public bool serializeSession
{
get
{
return CRB("serializeSession");
}
}
#endregion Protected Constructors
#region Protected Properties
/// <summary>
/// stringa conn x DB CONF
@@ -86,6 +89,19 @@ namespace SteamWare
}
}
#endregion Protected Properties
/// <summary>
/// Verifica se si debba serializzare ogni valore complesso (tabelle/righe) in sessione (per impiego di sessioni avanzate come Redis)
/// </summary>
public bool serializeSession
{
get
{
return CRB("serializeSession");
}
}
/// <summary>
/// init dei table adapters
/// </summary>
@@ -169,6 +185,80 @@ namespace SteamWare
}
}
/// <summary>
/// carica in ram oggetto AppConf
/// </summary>
/// <returns></returns>
protected Dictionary<string, string> ricaricaAppConf()
{
Dictionary<string, string> answ = new Dictionary<string, string>();
// istanzio un NUOVO oggetto x evitare problemi init contestuali
memLayer nML = new memLayer();
var tabDati = nML.taConfig.GetData();
// carico
foreach (DS_Utility.ConfigRow riga in tabDati)
{
try
{
answ.Add(riga.chiave, riga.valore);
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Errore procedura ricaricaAppConf per kvp: {0} / {1}{2}{3}", riga.chiave, riga.valore, Environment.NewLine, exc), tipoLog.EXCEPTION);
}
}
// log ricarica
logger.lg.scriviLog(string.Format("Effettuata procedura ricaricaAppConf per {0} records", answ.Count), tipoLog.INFO);
return answ;
}
/// <summary>
/// avvio oggetto AppConf in ram
/// </summary>
protected void startupAppConf()
{
// SOLO SE ho la chiave x abilitare config su DB...
if (confReadString("DbConfConnectionString") != "")
{
try
{
if (redKeyPresent(ACBH))
{
AppConf = new Dictionary<string, string>();
foreach (var item in redGetHash(ACBH))
{
if (AppConf.ContainsKey(item.Key))
{
AppConf[item.Key] = item.Value;
}
else
{
AppConf.Add(item.Key, item.Value);
}
}
}
else
{
AppConf = ricaricaAppConf();
KeyValuePair<string, string>[] valori = new KeyValuePair<string, string>[AppConf.Count];
int i = 0;
foreach (var item in AppConf)
{
valori[i] = new KeyValuePair<string, string>(item.Key, item.Value);
i++;
}
// salvo in redis valori (con TTL)
redSaveHash(ACBH, valori, maxAgeAppConf);
logger.lg.scriviLog("Completato procedura startupAppConf ", tipoLog.INFO);
}
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Errore in startupAppConf:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
}
}
}
/// <summary>
/// Configurations da tabella DB Config (short form wrapper)
/// </summary>
@@ -289,80 +379,6 @@ namespace SteamWare
startupAppConf();
}
/// <summary>
/// carica in ram oggetto AppConf
/// </summary>
/// <returns></returns>
protected Dictionary<string, string> ricaricaAppConf()
{
Dictionary<string, string> answ = new Dictionary<string, string>();
// istanzio un NUOVO oggetto x evitare problemi init contestuali
memLayer nML = new memLayer();
var tabDati = nML.taConfig.GetData();
// carico
foreach (DS_Utility.ConfigRow riga in tabDati)
{
try
{
answ.Add(riga.chiave, riga.valore);
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Errore procedura ricaricaAppConf per kvp: {0} / {1}{2}{3}", riga.chiave, riga.valore, Environment.NewLine, exc), tipoLog.EXCEPTION);
}
}
// log ricarica
logger.lg.scriviLog(string.Format("Effettuata procedura ricaricaAppConf per {0} records", answ.Count), tipoLog.INFO);
return answ;
}
/// <summary>
/// avvio oggetto AppConf in ram
/// </summary>
protected void startupAppConf()
{
// SOLO SE ho la chiave x abilitare config su DB...
if (confReadString("DbConfConnectionString") != "")
{
try
{
if (redKeyPresent(ACBH))
{
AppConf = new Dictionary<string, string>();
foreach (var item in redGetHash(ACBH))
{
if (AppConf.ContainsKey(item.Key))
{
AppConf[item.Key] = item.Value;
}
else
{
AppConf.Add(item.Key, item.Value);
}
}
}
else
{
AppConf = ricaricaAppConf();
KeyValuePair<string, string>[] valori = new KeyValuePair<string, string>[AppConf.Count];
int i = 0;
foreach (var item in AppConf)
{
valori[i] = new KeyValuePair<string, string>(item.Key, item.Value);
i++;
}
// salvo in redis valori (con TTL)
redSaveHash(ACBH, valori, maxAgeAppConf);
logger.lg.scriviLog("Completato procedura startupAppConf ", tipoLog.INFO);
}
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Errore in startupAppConf:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
}
}
}
#endregion area gestione config su DB
#region utility gestione conf settings
@@ -1408,6 +1424,11 @@ namespace SteamWare
ValDesc
}
/// <summary>
/// Oggetto currentDb locale
/// </summary>
private IDatabase _currDB { get; set; }
/// <summary>
/// Oggetto DB REDIS corrente
/// </summary>
@@ -1483,9 +1504,26 @@ namespace SteamWare
}
/// <summary>
/// Oggetto currentDb locale
/// Effettua comaprazione x CHIAVE in KVP ASC
/// </summary>
private IDatabase _currDB { get; set; }
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
private int CompareKey(KeyValuePair<string, int> x, KeyValuePair<string, int> y)
{
return x.Key.CompareTo(y.Key);
}
/// <summary>
/// Effettua comaprazione x CHIAVE in KVP DESC
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
private int CompareKeyDesc(KeyValuePair<string, int> x, KeyValuePair<string, int> y)
{
return y.Key.CompareTo(x.Key);
}
/// <summary>
/// Effettua comaprazione x VALORE in KVP ASC
@@ -1852,7 +1890,7 @@ namespace SteamWare
}
catch (Exception exc)
{
Log.Instance.Error(exc, $"{exc}", tipoLog.EXCEPTION);
SteamWare.Logger.Logging.LogException(exc, Logger.Constants.ERROR_LEVEL.Error);
}
return answ;
}
@@ -2251,28 +2289,6 @@ namespace SteamWare
return answ;
}
/// <summary>
/// Effettua comaprazione x CHIAVE in KVP ASC
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
private int CompareKey(KeyValuePair<string, int> x, KeyValuePair<string, int> y)
{
return x.Key.CompareTo(y.Key);
}
/// <summary>
/// Effettua comaprazione x CHIAVE in KVP DESC
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
private int CompareKeyDesc(KeyValuePair<string, int> x, KeyValuePair<string, int> y)
{
return y.Key.CompareTo(x.Key);
}
#endregion gestione valori in RedisCache
#region URL corretti immagini
@@ -2313,6 +2329,14 @@ namespace SteamWare
}
}
/// <summary>
/// Init accesso MongoDb
/// </summary>
private void setupMongo()
{
currMongoClient = new MongoClient(mongoConnString);
}
/// <summary>
/// Restituisce oggetto DB richiesto
/// </summary>
@@ -2324,14 +2348,6 @@ namespace SteamWare
return answ;
}
/// <summary>
/// Init accesso MongoDb
/// </summary>
private void setupMongo()
{
currMongoClient = new MongoClient(mongoConnString);
}
#endregion gestione mongoDb
}
}