Initial commit
This commit is contained in:
commit
137cb2ce13
215 changed files with 659023 additions and 0 deletions
26
src/GameCult.Logging/ConsoleLogger.cs
Normal file
26
src/GameCult.Logging/ConsoleLogger.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
|
||||
namespace GameCult.Logging
|
||||
{
|
||||
public class ConsoleLogger : ILogger
|
||||
{
|
||||
public void LogInfo(string message) => Console.WriteLine($"[INFO] {message}");
|
||||
public void LogWarning(string message)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine($"[WARN] {message}"); Console.ResetColor();
|
||||
}
|
||||
|
||||
public void LogError(string message)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"[ERROR] {message}"); Console.ResetColor();
|
||||
}
|
||||
|
||||
public void LogDebug(string message)
|
||||
{
|
||||
if(Environment.GetEnvironmentVariable("NODEV") is not null) Console.WriteLine($"[DEBUG] {message}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
25
src/GameCult.Logging/FileLogger.cs
Normal file
25
src/GameCult.Logging/FileLogger.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace GameCult.Logging
|
||||
{
|
||||
public class FileLogger : ILogger
|
||||
{
|
||||
private readonly string _logPath;
|
||||
|
||||
public FileLogger(string logPath = "server.log")
|
||||
{
|
||||
_logPath = logPath;
|
||||
}
|
||||
|
||||
private void Append(string level, string message)
|
||||
{
|
||||
File.AppendAllText(_logPath, $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{level}] {message}\n");
|
||||
}
|
||||
|
||||
public void LogInfo(string message) => Append("INFO", message);
|
||||
public void LogWarning(string message) => Append("WARN", message);
|
||||
public void LogError(string message) => Append("ERROR", message);
|
||||
public void LogDebug(string message) => Append("DEBUG", message);
|
||||
}
|
||||
}
|
||||
5
src/GameCult.Logging/GameCult.Logging.csproj
Normal file
5
src/GameCult.Logging/GameCult.Logging.csproj
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Description>Simple pluggable logging interface for CultLib</Description>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
19
src/GameCult.Logging/ILogger.cs
Normal file
19
src/GameCult.Logging/ILogger.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
namespace GameCult.Logging
|
||||
{
|
||||
public interface ILogger
|
||||
{
|
||||
void LogInfo(string message);
|
||||
void LogWarning(string message);
|
||||
void LogError(string message);
|
||||
void LogDebug(string message); // Optional; skip in prod
|
||||
}
|
||||
|
||||
// Null impl for no-op logging (e.g., perf tests)
|
||||
public class NullLogger : ILogger
|
||||
{
|
||||
public void LogInfo(string message) { }
|
||||
public void LogWarning(string message) { }
|
||||
public void LogError(string message) { }
|
||||
public void LogDebug(string message) { }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue