Code enhancements
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
//using System.Runtime.Remoting.Messaging;
|
||||
|
||||
// Filename: MarketDataTrace.cs
|
||||
// Author:Sean Kessler
|
||||
@@ -40,19 +37,16 @@ namespace MarketData
|
||||
/// <summary>WriteLine - Writes a line of text to trace log.</summary>
|
||||
/// <param name="message">string content of message to write.</param>
|
||||
/// <returns>void</returns>
|
||||
// [Conditional("TRACE")]
|
||||
public static void Write(LogLevel logLevel,string message)
|
||||
{
|
||||
if(MDTrace.logLevel<logLevel)return;
|
||||
Trace.Write(GetCallerIP()+GetThreadRep()+GetLogLevelRep()+"["+DateTime.Now.ToString()+"]"+GetMethodInfo()+message);
|
||||
Console.Write(message);
|
||||
Flush();
|
||||
}
|
||||
|
||||
/// <summary>WriteLine - Writes a line of text to trace log.</summary>
|
||||
/// <param name="message">string content of message to write.</param>
|
||||
/// <returns>void</returns>
|
||||
// [Conditional("TRACE")]
|
||||
public static void WriteLine(string message)
|
||||
{
|
||||
WriteLine(LogLevel.DEBUG,GetCallerIP()+GetThreadRep()+GetLogLevelRep()+"["+DateTime.Now.ToString()+"]"+" "+GetMethodInfo()+message);
|
||||
@@ -61,7 +55,6 @@ namespace MarketData
|
||||
/// <summary>WriteLine - Writes a line of text to trace log.</summary>
|
||||
/// <param name="message">string content of message to write.</param>
|
||||
/// <returns>void</returns>
|
||||
// [Conditional("TRACE")]
|
||||
public static void WriteLine(LogLevel logLevel,Exception exception)
|
||||
{
|
||||
if(MDTrace.logLevel<logLevel)return;
|
||||
@@ -72,7 +65,6 @@ namespace MarketData
|
||||
/// <summary>WriteLine - Writes a line of text to trace log.</summary>
|
||||
/// <param name="message">string content of message to write.</param>
|
||||
/// <returns>void</returns>
|
||||
// [Conditional("TRACE")]
|
||||
public static void WriteLine(LogLevel logLevel,string message)
|
||||
{
|
||||
if(MDTrace.logLevel<logLevel)return;
|
||||
@@ -82,21 +74,18 @@ namespace MarketData
|
||||
}
|
||||
/// <summary>Indent - set trace log indentation.</summary>
|
||||
/// <returns>void</returns>
|
||||
// [Conditional("TRACE")]
|
||||
public static void Indent()
|
||||
{
|
||||
Trace.Indent();
|
||||
}
|
||||
/// <summary>Unindent - set trace log indentation back.</summary>
|
||||
/// <returns>void</returns>
|
||||
// [Conditional("TRACE")]
|
||||
public static void Unindent()
|
||||
{
|
||||
Trace.Unindent();
|
||||
}
|
||||
/// <summary>Flush - Flush trace log buffers to disk.</summary>
|
||||
/// <returns>void</returns>
|
||||
// [Conditional("TRACE")]
|
||||
public static void Flush()
|
||||
{
|
||||
Trace.Flush();
|
||||
@@ -149,11 +138,6 @@ namespace MarketData
|
||||
private static String GetCallerIP()
|
||||
{
|
||||
return "[LOCAL]";
|
||||
// String hostName=(String)CallContext.GetData("HostName");
|
||||
// String hostAddress=(String)CallContext.GetData("HostAddress");
|
||||
// if(null!=hostName)hostName=hostName.Split('.')[0];
|
||||
// if(null==hostName && null==hostAddress)return "[LOCAL]";
|
||||
// return "["+hostAddress+"->"+hostName+"]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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