Loggin WIP
This commit is contained in:
9
src/Alma.Logging/Alma.Logging.csproj
Normal file
9
src/Alma.Logging/Alma.Logging.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
10
src/Alma.Logging/ILogger.cs
Normal file
10
src/Alma.Logging/ILogger.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Alma.Logging;
|
||||
|
||||
public interface ILogger<T>
|
||||
{
|
||||
LogLevel DefaultLogLevel { get; }
|
||||
void LogInformation(string logMessage);
|
||||
void LogDebug(string logMessage);
|
||||
void LogTrace(string logMessage);
|
||||
void Log(string logMessage, LogLevel logLevel);
|
||||
}
|
||||
7
src/Alma.Logging/ILoggerFactory.cs
Normal file
7
src/Alma.Logging/ILoggerFactory.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Alma.Logging;
|
||||
|
||||
public interface ILoggerFactory
|
||||
{
|
||||
ILogger<T> CreateLogger<T>();
|
||||
LogLevel DefaultLogLevel { get; }
|
||||
}
|
||||
8
src/Alma.Logging/LogLevel.cs
Normal file
8
src/Alma.Logging/LogLevel.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Alma.Logging;
|
||||
|
||||
public enum LogLevel
|
||||
{
|
||||
Information,
|
||||
Debug,
|
||||
Trace
|
||||
}
|
||||
25
src/Alma.Logging/Logger.cs
Normal file
25
src/Alma.Logging/Logger.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace Alma.Logging;
|
||||
|
||||
public class Logger<T> : ILogger<T>
|
||||
{
|
||||
public LogLevel DefaultLogLevel { get; }
|
||||
|
||||
public Logger(LogLevel defaultLogLevel)
|
||||
{
|
||||
DefaultLogLevel = defaultLogLevel;
|
||||
}
|
||||
|
||||
public void LogInformation(string s) => Log(s, LogLevel.Information);
|
||||
|
||||
public void LogDebug(string s) => Log(s, LogLevel.Debug);
|
||||
|
||||
public void LogTrace(string s) => Log(s, LogLevel.Trace);
|
||||
|
||||
public void Log(string s, LogLevel logLevel)
|
||||
{
|
||||
if (logLevel <= DefaultLogLevel)
|
||||
{
|
||||
Console.WriteLine(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
16
src/Alma.Logging/LoggerFactory.cs
Normal file
16
src/Alma.Logging/LoggerFactory.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Alma.Logging;
|
||||
|
||||
public class LoggerFactory : ILoggerFactory
|
||||
{
|
||||
public LogLevel DefaultLogLevel { get; }
|
||||
|
||||
public LoggerFactory(LogLevel defaultLogLevel = LogLevel.Information)
|
||||
{
|
||||
DefaultLogLevel = defaultLogLevel;
|
||||
}
|
||||
|
||||
public ILogger<T> CreateLogger<T>()
|
||||
{
|
||||
return new Logger<T>(DefaultLogLevel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user