mirror of
https://bitbucket.org/anguist/ntpa
synced 2026-10-06 03:39:49 +00:00
Stable version
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
// ActivityLog.cs
|
||||
//
|
||||
// Author:
|
||||
// Carsten Sonne Larsen <cs@innolan.net>
|
||||
// Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// Copyright (c) 2014 Carsten Sonne Larsen
|
||||
// Copyright (c) 2013 Carsten Sonne Larsen
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -23,7 +23,6 @@
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -31,69 +30,67 @@ namespace Ntp.Analyzer.Log
|
||||
{
|
||||
public class ActivityLog : LogBase, IEnumerable<String>
|
||||
{
|
||||
public ActivityLog()
|
||||
public ActivityLog ()
|
||||
{
|
||||
activity = new List<string>(2001);
|
||||
activity = new List<string> (2001);
|
||||
}
|
||||
|
||||
private readonly List<String> activity;
|
||||
private readonly Object locker = new Object();
|
||||
private readonly Object locker = new Object ();
|
||||
|
||||
public override void WriteLine(string text, Severity severity)
|
||||
public override void WriteLine (string text, Severity severity)
|
||||
{
|
||||
string severityText;
|
||||
|
||||
switch (severity)
|
||||
{
|
||||
case Severity.Error:
|
||||
severityText = "E";
|
||||
break;
|
||||
case Severity.Warn:
|
||||
severityText = "W";
|
||||
break;
|
||||
case Severity.Notice:
|
||||
severityText = "N";
|
||||
break;
|
||||
case Severity.Info:
|
||||
severityText = "I";
|
||||
break;
|
||||
case Severity.Debug:
|
||||
severityText = "D";
|
||||
break;
|
||||
default:
|
||||
throw new ApplicationException("Unknown severity level.");
|
||||
switch (severity) {
|
||||
case Severity.Error:
|
||||
severityText = "E";
|
||||
break;
|
||||
case Severity.Warn:
|
||||
severityText = "W";
|
||||
break;
|
||||
case Severity.Notice:
|
||||
severityText = "N";
|
||||
break;
|
||||
case Severity.Info:
|
||||
severityText = "I";
|
||||
break;
|
||||
case Severity.Debug:
|
||||
severityText = "D";
|
||||
break;
|
||||
default:
|
||||
throw new ApplicationException ("Unknown severity level.");
|
||||
}
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
string entry = String.Concat(
|
||||
now.ToString("HH:mm:ss"),
|
||||
" ", severityText, " ",
|
||||
text);
|
||||
string entry = String.Concat (
|
||||
now.ToString ("HH:mm:ss"),
|
||||
" ", severityText, " ",
|
||||
text);
|
||||
|
||||
lock (locker)
|
||||
{
|
||||
lock (locker) {
|
||||
if (activity.Count == 1000)
|
||||
activity.RemoveAt(0);
|
||||
activity.RemoveAt (0);
|
||||
|
||||
activity.Add(entry);
|
||||
activity.Add (entry);
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteLine(Exception exception)
|
||||
public override void WriteLine (Exception exception)
|
||||
{
|
||||
WriteLine(exception.Message, Severity.Error);
|
||||
WriteLine(exception.StackTrace, Severity.Debug);
|
||||
WriteLine (exception.Message, Severity.Error);
|
||||
WriteLine (exception.StackTrace, Severity.Debug);
|
||||
}
|
||||
|
||||
public IEnumerator<string> GetEnumerator()
|
||||
public IEnumerator<string> GetEnumerator ()
|
||||
{
|
||||
return activity.GetEnumerator();
|
||||
return activity.GetEnumerator ();
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return activity.GetEnumerator();
|
||||
return activity.GetEnumerator ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// LogBase.cs
|
||||
//
|
||||
// Author:
|
||||
// Carsten Sonne Larsen <cs@innolan.net>
|
||||
// Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// Copyright (c) 2014 Carsten Sonne Larsen
|
||||
// Copyright (c) 2013 Carsten Sonne Larsen
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -34,4 +34,4 @@ namespace Ntp.Analyzer.Log
|
||||
|
||||
public abstract void WriteLine(Exception exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
// LogConfiguration.cs
|
||||
//
|
||||
// Author:
|
||||
// Carsten Sonne Larsen <cs@innolan.net>
|
||||
// Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// Copyright (c) 2014 Carsten Sonne Larsen
|
||||
// Copyright (c) 2013 Carsten Sonne Larsen
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -23,7 +23,6 @@
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Ntp.Config;
|
||||
@@ -33,100 +32,90 @@ namespace Ntp.Analyzer.Log
|
||||
public sealed class LogConfiguration : ConfigurationBase
|
||||
{
|
||||
public const string Identifier = "Log";
|
||||
|
||||
private static readonly String[] Params = new[]
|
||||
{
|
||||
Identifier,
|
||||
"Severity",
|
||||
"File"
|
||||
};
|
||||
|
||||
private static readonly String[] Params = new[] {
|
||||
Identifier,
|
||||
"Severity",
|
||||
"File"
|
||||
};
|
||||
private readonly string file;
|
||||
private readonly Severity treshold;
|
||||
|
||||
private LogConfiguration(string configName, int indentLevel, string file, Severity treshold)
|
||||
private LogConfiguration (string configName, int indentLevel, string file, Severity treshold)
|
||||
: base(configName, indentLevel)
|
||||
{
|
||||
this.file = file;
|
||||
this.treshold = treshold;
|
||||
}
|
||||
|
||||
public string File
|
||||
{
|
||||
public string File {
|
||||
get { return file; }
|
||||
}
|
||||
|
||||
public Severity Treshold
|
||||
{
|
||||
public Severity Treshold {
|
||||
get { return treshold; }
|
||||
}
|
||||
|
||||
protected override IEnumerable<Object> Items
|
||||
{
|
||||
get
|
||||
{
|
||||
return new object[]
|
||||
{
|
||||
ConfigName,
|
||||
ConvertFromSeverity(Treshold),
|
||||
File
|
||||
};
|
||||
protected override IEnumerable<Object> Items {
|
||||
get {
|
||||
return new object[] {
|
||||
ConfigName,
|
||||
ConvertFromSeverity(Treshold),
|
||||
File
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
public override string ToString ()
|
||||
{
|
||||
return ConfigText(Params, Items);
|
||||
return ConfigText (Params, Items);
|
||||
}
|
||||
|
||||
public static LogConfiguration Create(ConfigurationBlock config)
|
||||
public static LogConfiguration Create (ConfigurationBlock config)
|
||||
{
|
||||
Dictionary<String, String> options = GetOptions(Params, config);
|
||||
Dictionary<String, String> options = GetOptions (Params, config);
|
||||
|
||||
return new LogConfiguration(
|
||||
GetOptionConfigName(options, Params[0], String.Empty, false),
|
||||
return new LogConfiguration (
|
||||
GetOptionConfigName (options, Params [0], String.Empty, false),
|
||||
config.IndentLevel,
|
||||
GetOptionString(options, Params[2], "Log", true),
|
||||
ConvertToSeverity(options[Params[1]])
|
||||
);
|
||||
GetOptionString (options, Params [2], "Log", true),
|
||||
ConvertToSeverity (options [Params [1]])
|
||||
);
|
||||
}
|
||||
|
||||
private static Severity ConvertToSeverity(string text)
|
||||
private static Severity ConvertToSeverity (string text)
|
||||
{
|
||||
switch (text.ToLower())
|
||||
{
|
||||
case "error":
|
||||
return Severity.Error;
|
||||
case "warn":
|
||||
return Severity.Warn;
|
||||
case "notice":
|
||||
return Severity.Notice;
|
||||
case "info":
|
||||
return Severity.Info;
|
||||
case "debug":
|
||||
return Severity.Debug;
|
||||
default:
|
||||
throw new ArgumentException("Unknown severity type: " + text);
|
||||
switch (text.ToLower ()) {
|
||||
case "error":
|
||||
return Severity.Error;
|
||||
case "warn":
|
||||
return Severity.Warn;
|
||||
case "notice":
|
||||
return Severity.Notice;
|
||||
case "info":
|
||||
return Severity.Info;
|
||||
case "debug":
|
||||
return Severity.Debug;
|
||||
default:
|
||||
throw new ArgumentException ("Unknown severity type: " + text);
|
||||
}
|
||||
}
|
||||
|
||||
private static string ConvertFromSeverity(Severity severity)
|
||||
private static string ConvertFromSeverity (Severity severity)
|
||||
{
|
||||
switch (severity)
|
||||
{
|
||||
case Severity.Error:
|
||||
return "error";
|
||||
case Severity.Warn:
|
||||
return "warn";
|
||||
case Severity.Notice:
|
||||
return "notice";
|
||||
case Severity.Info:
|
||||
return "info";
|
||||
case Severity.Debug:
|
||||
return "debug";
|
||||
default:
|
||||
throw new ArgumentException("Unknown severity type: " + severity);
|
||||
switch (severity) {
|
||||
case Severity.Error:
|
||||
return "error";
|
||||
case Severity.Warn:
|
||||
return "warn";
|
||||
case Severity.Notice:
|
||||
return "notice";
|
||||
case Severity.Info:
|
||||
return "info";
|
||||
case Severity.Debug:
|
||||
return "debug";
|
||||
default:
|
||||
throw new ArgumentException ("Unknown severity type: " + severity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
// LogFactory.cs
|
||||
//
|
||||
// Author:
|
||||
// Carsten Sonne Larsen <cs@innolan.net>
|
||||
// Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// Copyright (c) 2014 Carsten Sonne Larsen
|
||||
// Copyright (c) 2013 Carsten Sonne Larsen
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -49,4 +49,4 @@ namespace Ntp.Analyzer.Log
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
// LogGroup.cs
|
||||
//
|
||||
// Author:
|
||||
// Carsten Sonne Larsen <cs@innolan.net>
|
||||
// Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// Copyright (c) 2014 Carsten Sonne Larsen
|
||||
// Copyright (c) 2013 Carsten Sonne Larsen
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -55,4 +55,4 @@ namespace Ntp.Analyzer.Log
|
||||
logs.Add(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,13 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{909C8729-ED63-4603-85EA-34A1FC4D63D9}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Ntp.Analyzer.Log</RootNamespace>
|
||||
<AssemblyName>Ntp.Analyzer.Log</AssemblyName>
|
||||
<ReleaseVersion>8.9.0</ReleaseVersion>
|
||||
<ReleaseVersion>8.8.5</ReleaseVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// AssemblyInfo.cs
|
||||
//
|
||||
// Author:
|
||||
// Carsten Sonne Larsen <cs@innolan.net>
|
||||
// Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// Copyright (c) 2014 Carsten Sonne Larsen
|
||||
// Copyright (c) 2013 Carsten Sonne Larsen
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -34,7 +34,7 @@ using System.Reflection;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Innolan IT")]
|
||||
[assembly: AssemblyProduct("NTP Analyzer Log Library")]
|
||||
[assembly: AssemblyCopyright("Carsten Sonne Larsen <cs@innolan.net>")]
|
||||
[assembly: AssemblyCopyright("Carsten Sonne Larsen <cs@innolan.dk>")]
|
||||
[assembly: AssemblyTrademark("NTP Analyzer")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// Severity.cs
|
||||
//
|
||||
// Author:
|
||||
// Carsten Sonne Larsen <cs@innolan.net>
|
||||
// Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// Copyright (c) 2014 Carsten Sonne Larsen
|
||||
// Copyright (c) 2013 Carsten Sonne Larsen
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -34,4 +34,4 @@ namespace Ntp.Analyzer.Log
|
||||
Warn,
|
||||
Error
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
// TextLog.cs
|
||||
//
|
||||
// Author:
|
||||
// Carsten Sonne Larsen <cs@innolan.net>
|
||||
// Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// Copyright (c) 2014 Carsten Sonne Larsen
|
||||
// Copyright (c) 2013 Carsten Sonne Larsen
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -115,4 +115,4 @@ namespace Ntp.Analyzer.Log
|
||||
initialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user