mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
* Move to Central Package Management. Allows us to store NuGet package versions all in one place. Yay! * Update NuGet packages and fix code for changes. Notable: Changes to ILVerify. Npgsql doesn't need hacks for inet anymore, now we need hacks to make the old code work with this new reality. NUnit's analyzers are already complaining and I didn't even update it to 4.x yet. TerraFX changed to GetLastSystemError so error handling had to be changed. Buncha APIs have more NRT annotations. * Remove dotnet-eng NuGet package source. I genuinely don't know what this was for, and Central Package Management starts throwing warnings about it, so YEET. * Fix double loading of assemblies due to ALC shenanigans. Due to how the "sideloading" code for the ModLoader was set up, it would first try to load Microsoft.Extensions.Primitives from next to the content dll. But we already have that library in Robust! Chaos ensues. We now try to forcibly prioritize loading from the default ALC first to avoid this. * Remove Robust.Physics project. Never used. * Remove erroneous NVorbis reference. Should be VorbisPizza and otherwise wasn't used. * Sandbox fixes * Remove unused unit test package references. Castle.Core and NUnit.ConsoleRunner. * Update NUnit to 4.0.1 This requires replacing all the old assertion methods because they removed them 🥲 * Mute CA1416 (platform check) errors TerraFX started annotating APIs with this and I can't be arsed to entertain this analyzer so out it goes. * Fine ya cranky, no more CPM for Robust.Client.Injectors * Changelog * Oh so that's what dotnet-eng was used for. Yeah ok that makes sense. * Central package management for remaining 2 robust projects * Ok that was a bad idea let's just use NUnit 3 on the analyzer test project * Oh right forgot to remove this one * Update to a newer version of RemoteExecutor * Disable RemoteExecutor test https://github.com/dotnet/arcade/issues/8483 Yeah this package is not well maintained and clearly we can't rely on it. * Fix immutable list serialization
211 lines
6.0 KiB
C#
211 lines
6.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using Serilog;
|
|
using Serilog.Events;
|
|
using SLogger = Serilog.Core.Logger;
|
|
|
|
namespace Robust.Shared.Log
|
|
{
|
|
public sealed partial class LogManager
|
|
{
|
|
private sealed class Sawmill : ISawmill, IDisposable
|
|
{
|
|
// Need this to act as a proxy for some internal Serilog APIs related to message parsing.
|
|
private readonly SLogger _sLogger = new LoggerConfiguration().CreateLogger();
|
|
|
|
public string Name { get; }
|
|
|
|
public Sawmill? Parent { get; }
|
|
|
|
private bool _disposed;
|
|
|
|
public LogLevel? Level
|
|
{
|
|
get => _level;
|
|
set
|
|
{
|
|
if (Name == "root" && value == null)
|
|
{
|
|
throw new ArgumentException("Cannot set root sawmill level to null.");
|
|
}
|
|
|
|
_level = value;
|
|
}
|
|
}
|
|
|
|
private LogLevel? _level = null;
|
|
|
|
public List<ILogHandler> Handlers { get; } = new();
|
|
private readonly ReaderWriterLockSlim _handlerLock = new();
|
|
|
|
public Sawmill(Sawmill? parent, string name)
|
|
{
|
|
Parent = parent;
|
|
Name = name;
|
|
}
|
|
|
|
public void AddHandler(ILogHandler handler)
|
|
{
|
|
_handlerLock.EnterWriteLock();
|
|
try
|
|
{
|
|
Handlers.Add(handler);
|
|
}
|
|
finally
|
|
{
|
|
_handlerLock.ExitWriteLock();
|
|
}
|
|
}
|
|
|
|
public void RemoveHandler(ILogHandler handler)
|
|
{
|
|
_handlerLock.EnterWriteLock();
|
|
try
|
|
{
|
|
Handlers.Remove(handler);
|
|
}
|
|
finally
|
|
{
|
|
_handlerLock.ExitWriteLock();
|
|
}
|
|
}
|
|
|
|
public void Log(LogLevel level, Exception? exception, string message, params object?[] args)
|
|
{
|
|
if (!_sLogger.BindMessageTemplate(message, args, out var parsedTemplate, out var properties))
|
|
return;
|
|
|
|
var msg = new LogEvent(DateTimeOffset.Now, level.ToSerilog(), exception, parsedTemplate, properties);
|
|
LogInternal(Name, msg);
|
|
}
|
|
|
|
public void Log(LogLevel level, string message, params object?[] args)
|
|
{
|
|
if (args.Length != 0 && message.Contains("{0"))
|
|
{
|
|
// Fallback for logs that still use the string.Format approach.
|
|
message = string.Format(message, args);
|
|
args = Array.Empty<object>();
|
|
}
|
|
|
|
Log(level, null, message, args);
|
|
}
|
|
|
|
public void Log(LogLevel level, string message)
|
|
{
|
|
Log(level, message, Array.Empty<object>());
|
|
}
|
|
|
|
private void LogInternal(string sourceSawmill, LogEvent message)
|
|
{
|
|
if (message.Level.ToRobust() < GetPracticalLevel())
|
|
{
|
|
return;
|
|
}
|
|
|
|
_handlerLock.EnterReadLock();
|
|
try
|
|
{
|
|
if (_disposed)
|
|
{
|
|
throw new ObjectDisposedException(nameof(Sawmill));
|
|
}
|
|
|
|
foreach (var handler in Handlers)
|
|
{
|
|
handler.Log(sourceSawmill, message);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
_handlerLock.ExitReadLock();
|
|
}
|
|
|
|
Parent?.LogInternal(sourceSawmill, message);
|
|
}
|
|
|
|
private LogLevel GetPracticalLevel()
|
|
{
|
|
if (Level.HasValue)
|
|
{
|
|
return Level.Value;
|
|
}
|
|
|
|
return Parent?.GetPracticalLevel() ?? default;
|
|
}
|
|
|
|
public void Debug(string message, params object?[] args)
|
|
{
|
|
Log(LogLevel.Debug, message, args);
|
|
}
|
|
|
|
public void Debug(string message)
|
|
{
|
|
Log(LogLevel.Debug, message);
|
|
}
|
|
|
|
public void Info(string message, params object?[] args)
|
|
{
|
|
Log(LogLevel.Info, message, args);
|
|
}
|
|
|
|
public void Info(string message)
|
|
{
|
|
Log(LogLevel.Info, message);
|
|
}
|
|
|
|
public void Warning(string message, params object?[] args)
|
|
{
|
|
Log(LogLevel.Warning, message, args);
|
|
}
|
|
|
|
public void Warning(string message)
|
|
{
|
|
Log(LogLevel.Warning, message);
|
|
}
|
|
|
|
public void Error(string message, params object?[] args)
|
|
{
|
|
Log(LogLevel.Error, message, args);
|
|
}
|
|
|
|
public void Error(string message)
|
|
{
|
|
Log(LogLevel.Error, message);
|
|
}
|
|
|
|
public void Fatal(string message, params object?[] args)
|
|
{
|
|
Log(LogLevel.Fatal, message, args);
|
|
}
|
|
|
|
public void Fatal(string message)
|
|
{
|
|
Log(LogLevel.Fatal, message);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_handlerLock.EnterWriteLock();
|
|
try
|
|
{
|
|
_disposed = true;
|
|
|
|
foreach (ILogHandler handler in Handlers)
|
|
{
|
|
if (handler is IDisposable disposable)
|
|
{
|
|
disposable.Dispose();
|
|
}
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
_handlerLock.ExitWriteLock();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|