Code enhancements
This commit is contained in:
@@ -1,17 +1,11 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
using System.IO.Compression;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Win32;
|
||||
using System.Diagnostics;
|
||||
using MarketData.MarketDataModel;
|
||||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
using ThreadState=System.Threading.ThreadState;
|
||||
using System.Net;
|
||||
|
||||
namespace MarketData.Utils
|
||||
{
|
||||
@@ -78,44 +72,79 @@ namespace MarketData.Utils
|
||||
return date;
|
||||
}
|
||||
|
||||
public static void RemoveLogFiles(String strFolder=null)
|
||||
{
|
||||
if(null==strFolder)strFolder=Directory.GetCurrentDirectory();
|
||||
String[] logFiles=Directory.GetFiles(strFolder);
|
||||
if(null==logFiles || 0==logFiles.Length)return;
|
||||
logFiles=logFiles.Where(x => x.EndsWith(".log",StringComparison.InvariantCultureIgnoreCase)).ToArray<String>();
|
||||
if(null==logFiles || 0==logFiles.Length)return;
|
||||
// This is being called before any trace listeners have been added
|
||||
public static bool EnsureLogFolder(String strLogFolder)
|
||||
{
|
||||
if(Directory.Exists(strLogFolder))return true;
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(strLogFolder);
|
||||
return true;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExpireLogs(String pathLogFiles,int expiryDays)
|
||||
{
|
||||
DateTime currentDate = DateTime.Now;
|
||||
DateGenerator dateGenerator = new DateGenerator();
|
||||
String[] logFiles=Directory.GetFiles(pathLogFiles,"*.log");
|
||||
foreach(String logFile in logFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Removing {0}",logFile));
|
||||
File.Delete(logFile);
|
||||
DateTime creationTime = File.GetCreationTime(logFile);
|
||||
int age = dateGenerator.DaysBetweenActual(currentDate, creationTime);
|
||||
if(age>=expiryDays)
|
||||
{
|
||||
File.Delete(logFile);
|
||||
}
|
||||
}
|
||||
catch(Exception){;}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveLogFilesExcept(String exceptFile,String strFolder=null)
|
||||
{
|
||||
if(null==strFolder)strFolder=Directory.GetCurrentDirectory();
|
||||
String[] logFiles=Directory.GetFiles(strFolder,"*.log");
|
||||
if(null==logFiles || 0==logFiles.Length)return;
|
||||
logFiles=logFiles
|
||||
.Where(x => x.EndsWith(".log",StringComparison.InvariantCultureIgnoreCase) &&
|
||||
!x.EndsWith(exceptFile,StringComparison.InvariantCultureIgnoreCase)).ToArray<String>();
|
||||
// public static void RemoveLogFiles(String strFolder=null)
|
||||
// {
|
||||
// if(null==strFolder)strFolder=Directory.GetCurrentDirectory();
|
||||
// String[] logFiles=Directory.GetFiles(strFolder);
|
||||
// if(null==logFiles || 0==logFiles.Length)return;
|
||||
// logFiles=logFiles.Where(x => x.EndsWith(".log",StringComparison.InvariantCultureIgnoreCase)).ToArray<String>();
|
||||
// if(null==logFiles || 0==logFiles.Length)return;
|
||||
// foreach(String logFile in logFiles)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Removing {0}",logFile));
|
||||
// File.Delete(logFile);
|
||||
// }
|
||||
// catch(Exception){;}
|
||||
// }
|
||||
// }
|
||||
|
||||
if(null==logFiles || 0==logFiles.Length)return;
|
||||
foreach(String logFile in logFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Removing {0}",logFile));
|
||||
File.Delete(logFile);
|
||||
}
|
||||
catch(Exception){;}
|
||||
}
|
||||
}
|
||||
// public static void RemoveLogFilesExcept(String exceptFile,String strFolder=null)
|
||||
// {
|
||||
// if(null==strFolder)strFolder=Directory.GetCurrentDirectory();
|
||||
// String[] logFiles=Directory.GetFiles(strFolder,"*.log");
|
||||
// if(null==logFiles || 0==logFiles.Length)return;
|
||||
// logFiles=logFiles
|
||||
// .Where(x => x.EndsWith(".log",StringComparison.InvariantCultureIgnoreCase) &&
|
||||
// !x.EndsWith(exceptFile,StringComparison.InvariantCultureIgnoreCase)).ToArray<String>();
|
||||
|
||||
// if(null==logFiles || 0==logFiles.Length)return;
|
||||
// foreach(String logFile in logFiles)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Removing {0}",logFile));
|
||||
// File.Delete(logFile);
|
||||
// }
|
||||
// catch(Exception){;}
|
||||
// }
|
||||
// }
|
||||
|
||||
public static String Pad(string str, char filler, int length)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user