From d489d25554b6beb3675c9fe00daffdcbdffdea90 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 22 Feb 2020 09:02:47 +0100 Subject: [PATCH] Fix eccezioni logging --- IOB-MAN/IOBManPanel.cs | 10 ++- IOB-UT/IOB-UT.csproj | 1 + IOB-UT/Logging.cs | 40 +++++++++++ IOB-UT/RedisMan.cs | 131 +++++++++++++++++++++------------- IOB-WIN/GlobalSuppressions.cs | 31 ++++++++ 5 files changed, 162 insertions(+), 51 deletions(-) create mode 100644 IOB-UT/Logging.cs diff --git a/IOB-MAN/IOBManPanel.cs b/IOB-MAN/IOBManPanel.cs index 9f019af5..c774ee7f 100644 --- a/IOB-MAN/IOBManPanel.cs +++ b/IOB-MAN/IOBManPanel.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using SteamWare.Logger; using System; using System.Collections.Generic; using System.Configuration; @@ -399,7 +400,9 @@ namespace IOB_MAN result.Wait(); } catch (Exception exc) - { } + { + Logging.Instance.Error($"MainTimer_Tick {exc}"); + } } MainTimer.Start(); } @@ -415,7 +418,9 @@ namespace IOB_MAN result.Wait(); } catch (Exception exc) - { } + { + Logging.Instance.Error($"forceCheckTimer_Tick {exc}"); + } } checkWatchdog(); // riavvio i timer x sicurezza... @@ -997,7 +1002,6 @@ namespace IOB_MAN private void apriChildSel() { - int pid = -1; // SOLO SE selezionato in dgv... if (dgvManagedItems.SelectedRows.Count > 0) { diff --git a/IOB-UT/IOB-UT.csproj b/IOB-UT/IOB-UT.csproj index 398a9d3f..6c7757d4 100644 --- a/IOB-UT/IOB-UT.csproj +++ b/IOB-UT/IOB-UT.csproj @@ -106,6 +106,7 @@ + diff --git a/IOB-UT/Logging.cs b/IOB-UT/Logging.cs new file mode 100644 index 00000000..152632f1 --- /dev/null +++ b/IOB-UT/Logging.cs @@ -0,0 +1,40 @@ +using NLog; +using NLog.Config; +using NLog.Targets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace IOB_UT +{/// + /// Classe helper x LOG basata su NLog + /// + public static class Logging + { + /// + /// S + /// + public static NLog.Logger Instance { get; private set; } + 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); + +#endif + + LogManager.ReconfigExistingLoggers(); + + Instance = LogManager.GetCurrentClassLogger(); + } + } +} diff --git a/IOB-UT/RedisMan.cs b/IOB-UT/RedisMan.cs index c302aba3..97272072 100644 --- a/IOB-UT/RedisMan.cs +++ b/IOB-UT/RedisMan.cs @@ -28,8 +28,10 @@ namespace IOB_UT sb.AppendLine($"Status: {connRedis.GetStatus()}"); answ = sb.ToString(); } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"getRedisInfoData {exc}"); + } return answ; } /// @@ -76,8 +78,10 @@ namespace IOB_UT { answ = string.Format($"{baseUtils.CRS("appName")}:{keyName}"); } - catch - { } + catch(Exception exc) + { + Logging.Instance.Error($"redHash {exc}"); + } return answ; } /// @@ -92,7 +96,10 @@ namespace IOB_UT { answ = JsonConvert.SerializeObject(origVal); } - catch { } + catch (Exception exc) + { + Logging.Instance.Error($"serializeVal {exc}"); + } return answ; } /// @@ -107,7 +114,10 @@ namespace IOB_UT { answ = JsonConvert.DeserializeObject(serVal); } - catch { } + catch (Exception exc) + { + Logging.Instance.Error($"deserializeVal {exc}"); + } return answ; } /// @@ -176,7 +186,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("{0}", exc), tipoLog.EXCEPTION); + Logging.Instance.Error($"redServInfo {exc}"); } return answ; } @@ -194,7 +204,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("Errore in getRSV:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); + Logging.Instance.Info($"getRSV {exc}"); } return answ; } @@ -214,7 +224,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("Errore in setRSV:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); + Logging.Instance.Error($"setRSV {exc}"); } return answ; } @@ -237,7 +247,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("Errore in setRSV:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); + Logging.Instance.Error($"setRSV {exc}"); } return answ; } @@ -255,7 +265,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("Errore in setRCI:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); + Logging.Instance.Error($"setRCntI {exc}"); } return answ; } @@ -273,7 +283,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("Errore in setRCD:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); + Logging.Instance.Error($"setRCntD {exc}"); } return answ; } @@ -293,7 +303,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("Errore in getRSV:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); + Logging.Instance.Error($"getRCnt {exc}"); } return answInt; } @@ -311,7 +321,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("Errore in resetRCnt:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); + Logging.Instance.Error($"resetRCnt {exc}"); } return answ; } @@ -329,7 +339,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("Errore in getRKeys:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); + Logging.Instance.Error($"getRKeys {exc}"); } return answ; } @@ -348,7 +358,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("Errore in setRKeys:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); + Logging.Instance.Error($"setRKeys {exc}"); } return answ; } @@ -367,7 +377,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("Errore in redKeyPresent per la key {2}:{0}{1}", Environment.NewLine, exc, key), tipoLog.EXCEPTION); + Logging.Instance.Error($"redKeyPresent {exc}"); } return answ; } @@ -384,8 +394,10 @@ namespace IOB_UT RedisKey chiave = key; answ = redKeyPresent(chiave); } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"redKeyPresentSz {exc}"); + } return answ; } /// @@ -403,7 +415,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("Errore in redHashPresent per la key {2}{0}{1}", Environment.NewLine, exc, key), tipoLog.EXCEPTION); + Logging.Instance.Error($"redHashPresent {exc}"); } return answ; } @@ -420,8 +432,10 @@ namespace IOB_UT RedisKey chiave = key; answ = redHashPresent(chiave); } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"redHashPresentSz {exc}"); + } return answ; } /// @@ -445,8 +459,10 @@ namespace IOB_UT i++; } } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"redGetHash {exc}"); + } return answ; } /// @@ -467,8 +483,10 @@ namespace IOB_UT answ.Add(item.Name, item.Value); } } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"redGetHashDict {exc}"); + } return answ; } /// @@ -488,8 +506,10 @@ namespace IOB_UT RedisValue valOut = cache.HashGet(chiave, campo); answ = valOut.ToString(); } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"redGetHashField {exc}"); + } return answ; } /// @@ -515,8 +535,10 @@ namespace IOB_UT cache.HashSet(chiave, valori); answ = true; } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"redSaveHash {exc}"); + } return answ; } /// @@ -542,8 +564,10 @@ namespace IOB_UT cache.HashSet(chiave, valori); answ = true; } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"redSaveHashDict {exc}"); + } return answ; } @@ -573,8 +597,10 @@ namespace IOB_UT cache.HashSet(chiave, valori); answ = true; } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"redSaveHashList {exc}"); + } } return answ; } @@ -597,10 +623,11 @@ namespace IOB_UT { cache.KeyExpire(chiave, DateTime.Now.AddSeconds(expireSeconds)); } - //answ = true; } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"redSaveHash {exc}"); + } return answ; } /// @@ -624,8 +651,10 @@ namespace IOB_UT } //answ = true; } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"redSaveHashDict {exc}"); + } return answ; } /// @@ -643,8 +672,10 @@ namespace IOB_UT cache.KeyDelete(chiave); answ = true; } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"redDelKey {exc}"); + } return answ; } /// @@ -673,7 +704,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("{0}", exc), tipoLog.EXCEPTION); + Logging.Instance.Error($"redFlushKey {exc}"); } return answ; } @@ -701,7 +732,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("{0}", exc), tipoLog.EXCEPTION); + Logging.Instance.Error($"redCountKey {exc}"); } return answ; } @@ -722,8 +753,10 @@ namespace IOB_UT answ += server.DatabaseSize(); } } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"numRecRedis {exc}"); + } return answ; } } @@ -757,7 +790,7 @@ namespace IOB_UT } catch (Exception exc) { - //logger.lg.scriviLog(string.Format("{0}", exc), tipoLog.EXCEPTION); + Logging.Instance.Error($"redGetCounterByKey 01 {exc}"); } // ora recupero valori! var valori = getRKeys(chiavi); @@ -771,8 +804,10 @@ namespace IOB_UT answ.Add(new KeyValuePair(chiavi[i], currVal)); } } - catch - { } + catch (Exception exc) + { + Logging.Instance.Error($"redGetCounterByKey 02 {exc}"); + } // se richiesto riordino... switch (orderBy) { diff --git a/IOB-WIN/GlobalSuppressions.cs b/IOB-WIN/GlobalSuppressions.cs index 501cc26b..35bbaf73 100644 --- a/IOB-WIN/GlobalSuppressions.cs +++ b/IOB-WIN/GlobalSuppressions.cs @@ -6,3 +6,34 @@ [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Gli identificatori non devono contenere caratteri di sottolineatura", Justification = "", Scope = "namespace", Target = "~N:IOB_WIN")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1305:Specificare IFormatProvider", Justification = "", Scope = "member", Target = "~M:IOB_WIN.IobSiemensSaet.processWhatchDog")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Non passare valori letterali come parametri localizzati", Justification = "", Scope = "member", Target = "~M:IOB_WIN.IobSiemensSaet.#ctor(IOB_WIN.AdapterForm,IOB_WIN.IobConfiguration)")] + +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.lastUrl")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlAddPzCount")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlAlive")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlForceSplit")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlGetCurrODL")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlGetParams2Write")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlGetPzCount")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlGetPzCountRec")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlGetTask2Exe")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlIdleTime")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlInizioOdlIob")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlIobEnabled")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlReboot")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlRemTask2Exe")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlSaveAllParams")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlSaveMemMap")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlSetM2IOB")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlSetOptVal")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlSetPzCount")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlSetPzCountMAC")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobGeneric.urlUpdateWriteParams")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.IobMTC.urlSaveDataItems")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.MainForm.updateUrl")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.MainForm.urlAlive")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.MainForm.urlDownloadFile")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.MainForm.urlDownloadFileCloud")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.MainForm.urlIob2call")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.MainForm.urlReboot")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.MainForm.urlUploadFile")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Le proprietà Uri non devono essere stringhe", Justification = "", Scope = "member", Target = "~P:IOB_WIN.MainForm.urlUploadFileCloud")] \ No newline at end of file