Changes
This commit is contained in:
parent
e7f284052e
commit
115ab629dc
@ -3,6 +3,13 @@ using System.IO;
|
|||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
TODO:
|
||||||
|
x)
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
namespace lib
|
namespace lib
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -82,6 +89,8 @@ namespace lib
|
|||||||
Config cfg = null;
|
Config cfg = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
if( File.Exists( filename ) )
|
||||||
{
|
{
|
||||||
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
|
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
|
||||||
|
|
||||||
@ -91,13 +100,27 @@ namespace lib
|
|||||||
|
|
||||||
cfg.SetFilename( filename );
|
cfg.SetFilename( filename );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cfg = CreateTemplate( filename, t );
|
||||||
|
}
|
||||||
|
}
|
||||||
catch( IOException )
|
catch( IOException )
|
||||||
|
{
|
||||||
|
cfg = CreateTemplate( filename, t );
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Config CreateTemplate( string filename, Type t )
|
||||||
{
|
{
|
||||||
Type[] types = new Type[0];
|
Type[] types = new Type[0];
|
||||||
object[] parms = new object[0];
|
object[] parms = new object[0];
|
||||||
|
|
||||||
//types[ 0 ] = typeof( string );
|
//types[ 0 ] = typeof( string );
|
||||||
//parms[ 0 ] = filename;
|
//parms[ 0 ] = filename;
|
||||||
|
Config cfg = null;
|
||||||
|
|
||||||
ConstructorInfo cons = t?.GetConstructor(types);
|
ConstructorInfo cons = t?.GetConstructor(types);
|
||||||
|
|
||||||
@ -124,7 +147,6 @@ namespace lib
|
|||||||
|
|
||||||
Config.save( cfg, templateFile );
|
Config.save( cfg, templateFile );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
@ -146,7 +168,7 @@ namespace lib
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private string m_filename = "";
|
private string m_filename = "{unknown}";
|
||||||
|
|
||||||
public Config()
|
public Config()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -276,6 +276,7 @@ static public class log
|
|||||||
writeToAll( evt );
|
writeToAll( evt );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO PERF Replace this with a semaphore/mutex
|
||||||
Thread.Sleep( 0 );
|
Thread.Sleep( 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,6 +321,37 @@ static public class log
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setConsoleColor( log.LogEvent evt )
|
||||||
|
{
|
||||||
|
switch( evt.LogType )
|
||||||
|
{
|
||||||
|
case log.LogType.Trace:
|
||||||
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||||
|
break;
|
||||||
|
case log.LogType.Debug:
|
||||||
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
break;
|
||||||
|
case log.LogType.Info:
|
||||||
|
Console.ForegroundColor = ConsoleColor.DarkGreen;
|
||||||
|
break;
|
||||||
|
case log.LogType.High:
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
break;
|
||||||
|
case log.LogType.Warn:
|
||||||
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
break;
|
||||||
|
case log.LogType.Error:
|
||||||
|
Console.ForegroundColor = ConsoleColor.DarkRed;
|
||||||
|
Console.BackgroundColor = ConsoleColor.DarkGray;
|
||||||
|
break;
|
||||||
|
case log.LogType.Fatal:
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.BackgroundColor = ConsoleColor.DarkGray;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static private void writeToAll( LogEvent evt )
|
static private void writeToAll( LogEvent evt )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -329,6 +361,7 @@ static public class log
|
|||||||
{
|
{
|
||||||
char sym = getSymbol( evt.LogType );
|
char sym = getSymbol( evt.LogType );
|
||||||
|
|
||||||
|
|
||||||
var truncatedCat = evt.Cat.Substring( 0, Math.Min( 8, evt.Cat.Length ) );
|
var truncatedCat = evt.Cat.Substring( 0, Math.Min( 8, evt.Cat.Length ) );
|
||||||
|
|
||||||
string finalLine = string.Format( "{0,-8}{1}| {2}", truncatedCat, sym, evt.Msg );
|
string finalLine = string.Format( "{0,-8}{1}| {2}", truncatedCat, sym, evt.Msg );
|
||||||
@ -338,7 +371,10 @@ static public class log
|
|||||||
|
|
||||||
s_writer.WriteLine( finalLine );
|
s_writer.WriteLine( finalLine );
|
||||||
|
|
||||||
|
setConsoleColor( evt );
|
||||||
Console.WriteLine( finalLine );
|
Console.WriteLine( finalLine );
|
||||||
|
Console.ResetColor();
|
||||||
|
|
||||||
|
|
||||||
Debug.WriteLine( finalLine );
|
Debug.WriteLine( finalLine );
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,7 @@ namespace res
|
|||||||
//For serialization
|
//For serialization
|
||||||
public Ref()
|
public Ref()
|
||||||
:
|
:
|
||||||
base( "<unknown>" )
|
base( "{unknown}" )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user