basic implementation

This commit is contained in:
Ellpeck 2020-07-23 02:26:45 +02:00
parent d2aa2e1b32
commit 4617ef5a00
3 changed files with 34 additions and 1 deletions

View file

@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtremelySimpleLogger", "ExtremelySimpleLogger\ExtremelySimpleLogger.csproj", "{D323F21E-8DE7-46DB-8E34-E4739876F6CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{50C64522-C1E8-495D-9E9B-3B6A21551D3B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -12,5 +14,9 @@ Global
{D323F21E-8DE7-46DB-8E34-E4739876F6CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D323F21E-8DE7-46DB-8E34-E4739876F6CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D323F21E-8DE7-46DB-8E34-E4739876F6CB}.Release|Any CPU.Build.0 = Release|Any CPU
{50C64522-C1E8-495D-9E9B-3B6A21551D3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50C64522-C1E8-495D-9E9B-3B6A21551D3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50C64522-C1E8-495D-9E9B-3B6A21551D3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50C64522-C1E8-495D-9E9B-3B6A21551D3B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View file

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
</Project>

View file

@ -1,7 +1,33 @@
using System;
using System.Collections.Generic;
namespace ExtremelySimpleLogger {
public class Logger {
public List<Sink> Sinks { get; set; } = new List<Sink>();
public LogLevel MinimumLevel { get; set; } = LogLevel.Trace;
public bool IsEnabled { get; set; } = true;
public string Name { get; set; }
public Logger(string name = "") {
this.Name = name;
}
public void Log(LogLevel level, object message, Exception e = null) {
if (!this.IsEnabled || level < this.MinimumLevel)
return;
foreach (var sink in this.Sinks) {
if (level >= sink.MinimumLevel)
sink.Log(this, level, message, e);
}
}
public void Trace(object message) => this.Log(LogLevel.Trace, message);
public void Debug(object message) => this.Log(LogLevel.Debug, message);
public void Info(object message) => this.Log(LogLevel.Info, message);
public void Warn(object message, Exception e = null) => this.Log(LogLevel.Warn, message, e);
public void Error(object message, Exception e = null) => this.Log(LogLevel.Error, message, e);
public void Fatal(object message, Exception e = null) => this.Log(LogLevel.Fatal, message, e);
}
}