Trovato compromesso x mitigazione LOG
This commit is contained in:
+114
-108
@@ -62,6 +62,16 @@ namespace SteamWare
|
||||
{
|
||||
#region dichiarazione variabili
|
||||
|
||||
/// <summary>
|
||||
/// metodo gestione wirteLock su file log
|
||||
/// </summary>
|
||||
private static ReaderWriterLockSlim _readWriteLock = new ReaderWriterLockSlim();
|
||||
|
||||
/// <summary>
|
||||
/// Ultima verifica directory (x shrink)
|
||||
/// </summary>
|
||||
private static DateTime lastDirCheck;
|
||||
|
||||
/// <summary>
|
||||
/// controlla se si debba mantenere sotto controllo la dimensioen della cartella logs
|
||||
/// </summary>
|
||||
@@ -87,16 +97,6 @@ namespace SteamWare
|
||||
/// </summary>
|
||||
protected bool enableDumpDiag = false;
|
||||
|
||||
/// <summary>
|
||||
/// metodo gestione wirteLock su file log
|
||||
/// </summary>
|
||||
private static ReaderWriterLockSlim _readWriteLock = new ReaderWriterLockSlim();
|
||||
|
||||
/// <summary>
|
||||
/// Ultima verifica directory (x shrink)
|
||||
/// </summary>
|
||||
private static DateTime lastDirCheck;
|
||||
|
||||
#endregion dichiarazione variabili
|
||||
|
||||
#region metodi esposti
|
||||
@@ -179,6 +179,91 @@ namespace SteamWare
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Vera chiamata scrittura log x override con gestione REDIS di calmierazione
|
||||
/// </summary>
|
||||
/// <param name="_testoPre"></param>
|
||||
/// <returns></returns>
|
||||
private bool doScriviLog(string _testoPre)
|
||||
{
|
||||
bool fatto = false;
|
||||
// attenzione: rimpiazzo eventuali "</br>" con newline...
|
||||
string _testo = string.Format("{0:H:mm:ss ffff} \t{1}", DateTime.Now, _testoPre.Replace("<br>", Environment.NewLine).Replace("<br/>", Environment.NewLine).Replace("<br />", Environment.NewLine));
|
||||
// se è configurato x shrink ed è passato almeno 1 gg da ultimo check...
|
||||
if (_doShrinkFolder && lastDirCheck.AddDays(1) < DateTime.Now)
|
||||
{
|
||||
// verifica dim directory ed eventualmente cancella... - opzionale
|
||||
shrinkDir();
|
||||
// salvo nuova ora di check
|
||||
lastDirCheck = DateTime.Now;
|
||||
}
|
||||
// (ri)genera il nome del file di log...
|
||||
newLogfileName();
|
||||
// scrivo thread safe
|
||||
fatto = WriteToFileThreadSafe(_logfileName, _testo);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua verifica e pulizia eventuali vecchi messaggi errore...
|
||||
/// </summary>
|
||||
private void purgeOldVeto()
|
||||
{
|
||||
// limite minimo di chaivi salvate per cui procedere coi controlli
|
||||
int checkLimit = 100;
|
||||
// limito cleanup x avere un operazione graduale...
|
||||
int maxCleanup = checkLimit / 2;
|
||||
// parto recuperando i valori VETO.... se > 100...
|
||||
string redKeyCounters = memLayer.ML.redHash("Logger:Counter:*");
|
||||
string redLastCheck = memLayer.ML.redHash("Logger:CheckLock");
|
||||
// se non ho un veto check...
|
||||
if (string.IsNullOrEmpty(memLayer.ML.getRSV(redLastCheck)))
|
||||
{
|
||||
memLayer.ML.setRSV(redLastCheck, "LOCK", 10);
|
||||
int numCount = memLayer.ML.redCountKey(redKeyCounters);
|
||||
if (numCount > checkLimit)
|
||||
{
|
||||
var redKeysList2check = memLayer.ML.redGetKeys(redKeyCounters);
|
||||
foreach (var item in redKeysList2check)
|
||||
{
|
||||
// cerco il duale... se NON lo trovo
|
||||
if (!memLayer.ML.redHashPresentSz(item.ToString().Replace(":Logger:Counter:", ":Logger:Veto:")))
|
||||
{
|
||||
//// loggo!
|
||||
//doScriviLog(item);
|
||||
// elimino...
|
||||
memLayer.ML.redDelKey(item);
|
||||
maxCleanup--;
|
||||
}
|
||||
if (maxCleanup <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// formatta un blococ di diagnostica (titolo, contenuto / eccezione)
|
||||
/// </summary>
|
||||
/// <param name="titolo"></param>
|
||||
/// <param name="contenuto"></param>
|
||||
/// <returns></returns>
|
||||
protected string formDiagBlock(string titolo, string contenuto)
|
||||
{
|
||||
string answ = SteamwareStrings.charTitle(titolo, '-', 60);
|
||||
try
|
||||
{
|
||||
answ += SteamwareStrings.addLine(contenuto);
|
||||
}
|
||||
catch
|
||||
{
|
||||
answ += string.Format("Errore diagnostica {0}", titolo);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il numero di chiavi di vedo e di chiavi di count ative
|
||||
/// </summary>
|
||||
@@ -449,89 +534,29 @@ namespace SteamWare
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// formatta un blococ di diagnostica (titolo, contenuto / eccezione)
|
||||
/// </summary>
|
||||
/// <param name="titolo"></param>
|
||||
/// <param name="contenuto"></param>
|
||||
/// <returns></returns>
|
||||
protected string formDiagBlock(string titolo, string contenuto)
|
||||
{
|
||||
string answ = SteamwareStrings.charTitle(titolo, '-', 60);
|
||||
try
|
||||
{
|
||||
answ += SteamwareStrings.addLine(contenuto);
|
||||
}
|
||||
catch
|
||||
{
|
||||
answ += string.Format("Errore diagnostica {0}", titolo);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Vera chiamata scrittura log x override con gestione REDIS di calmierazione
|
||||
/// </summary>
|
||||
/// <param name="_testoPre"></param>
|
||||
/// <returns></returns>
|
||||
private bool doScriviLog(string _testoPre)
|
||||
{
|
||||
bool fatto = false;
|
||||
// attenzione: rimpiazzo eventuali "</br>" con newline...
|
||||
string _testo = string.Format("{0:H:mm:ss ffff} \t{1}", DateTime.Now, _testoPre.Replace("<br>", Environment.NewLine).Replace("<br/>", Environment.NewLine).Replace("<br />", Environment.NewLine));
|
||||
// se è configurato x shrink ed è passato almeno 1 gg da ultimo check...
|
||||
if (_doShrinkFolder && lastDirCheck.AddDays(1) < DateTime.Now)
|
||||
{
|
||||
// verifica dim directory ed eventualmente cancella... - opzionale
|
||||
shrinkDir();
|
||||
// salvo nuova ora di check
|
||||
lastDirCheck = DateTime.Now;
|
||||
}
|
||||
// (ri)genera il nome del file di log...
|
||||
newLogfileName();
|
||||
// scrivo thread safe
|
||||
fatto = WriteToFileThreadSafe(_logfileName, _testo);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua verifica e pulizia eventuali vecchi messaggi errore...
|
||||
/// </summary>
|
||||
private void purgeOldVeto()
|
||||
{
|
||||
// limite minimo di chaivi salvate per cui procedere coi controlli
|
||||
int checkLimit = 100;
|
||||
// limito cleanup x avere un operazione graduale...
|
||||
int maxCleanup = checkLimit / 2;
|
||||
// parto recuperando i valori VETO.... se > 100...
|
||||
string redKeyCounters = memLayer.ML.redHash("Logger:Counter:*");
|
||||
int numCount = memLayer.ML.redCountKey(redKeyCounters);
|
||||
if (numCount > checkLimit)
|
||||
{
|
||||
var redKeysList2check = memLayer.ML.redGetKeys(redKeyCounters);
|
||||
foreach (StackExchange.Redis.RedisKey item in redKeysList2check)
|
||||
{
|
||||
// cerco il duale... se NON lo trovo
|
||||
if (!memLayer.ML.redHashPresentSz(item.ToString().Replace(":Logger:Counter:", ":Logger:Veto:")))
|
||||
{
|
||||
// loggo!
|
||||
doScriviLog(item);
|
||||
// elimino...
|
||||
memLayer.ML.redDelKey(item);
|
||||
maxCleanup--;
|
||||
}
|
||||
if (maxCleanup <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion metodi esposti
|
||||
|
||||
#region metodi privati
|
||||
|
||||
private void compressAndRemove(FileInfo[] _fis)
|
||||
{
|
||||
foreach (FileInfo _file in _fis)
|
||||
{
|
||||
if (_file.CreationTime < DateTime.Now.AddDays(-2)) // zippo files + vecchi di 2 gg...
|
||||
{
|
||||
fileMover.obj.zippaSingoloFile(_file);
|
||||
// cancello l'originale...
|
||||
fileMover.obj.eliminaFile(_file);
|
||||
}
|
||||
}
|
||||
// verifico directory e dimensione...
|
||||
while (fileMover.obj.totalMb() > _logMaxMb)
|
||||
{
|
||||
// cancello i + vecchi fino a rientrare alla dimensione max...
|
||||
fileMover.obj.deleteOldest();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// fornisce il file + vecchio
|
||||
/// </summary>
|
||||
@@ -576,25 +601,6 @@ namespace SteamWare
|
||||
compressAndRemove(_fis);
|
||||
}
|
||||
|
||||
private void compressAndRemove(FileInfo[] _fis)
|
||||
{
|
||||
foreach (FileInfo _file in _fis)
|
||||
{
|
||||
if (_file.CreationTime < DateTime.Now.AddDays(-2)) // zippo files + vecchi di 2 gg...
|
||||
{
|
||||
fileMover.obj.zippaSingoloFile(_file);
|
||||
// cancello l'originale...
|
||||
fileMover.obj.eliminaFile(_file);
|
||||
}
|
||||
}
|
||||
// verifico directory e dimensione...
|
||||
while (fileMover.obj.totalMb() > _logMaxMb)
|
||||
{
|
||||
// cancello i + vecchi fino a rientrare alla dimensione max...
|
||||
fileMover.obj.deleteOldest();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion metodi privati
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ namespace TestBench
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto REDIS
|
||||
/// </summary>
|
||||
@@ -19,14 +21,30 @@ namespace TestBench
|
||||
|
||||
private StackExchange.Redis.ISubscriber subscriber;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
myInitComponent();
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
|
||||
|
||||
#region Private Delegates
|
||||
|
||||
private delegate void SetTextCallback(string text);
|
||||
|
||||
#endregion Private Delegates
|
||||
|
||||
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void actionTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
// processo le varie azioni...
|
||||
@@ -136,9 +154,14 @@ namespace TestBench
|
||||
private void chkTestLogger_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (chkTestLogger.Checked)
|
||||
{
|
||||
LogTimer.Interval = 50;
|
||||
LogTimer.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogTimer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void clockTimer_Tick(object sender, EventArgs e)
|
||||
@@ -252,5 +275,7 @@ namespace TestBench
|
||||
lblQueueRead.Text = $"{myRedis.ListPop(myKey)}{Environment.NewLine}{lblQueueRead.Text}";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user