Skip to content

A Serilog Sink for Garry's Mod Clients and Servers

License

Notifications You must be signed in to change notification settings

GmodNET/GmodSerilog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3ffb9c2 · Nov 10, 2021

History

64 Commits
Nov 10, 2021
Oct 28, 2021
Nov 10, 2021
Jun 30, 2021
Jun 26, 2021
Apr 26, 2021
Jul 11, 2021
Nov 10, 2021
Jun 30, 2021
Apr 26, 2021
Jun 27, 2021
Oct 28, 2021

Repository files navigation

GmodSerilog

NuGet Link

A Serilog Sink for Garry's Mod clients' and servers' consoles for GmodDotNet modules.

Usage

GmodNET.Serilog.Sink can be used with Serilog logger as any other standard sink by calling corresponding extension method on LoggerSinkConfiguration. Here is an example of usage of GmodNET.Serilog.Sink with GmodDotNet module:

using GmodNET.API;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using GmodNET.Serilog.Sink;

namespace Tests
{
    public class ExampleModule : IModule
    {
        public string ModuleName => "ExampleModule";

        public string ModuleVersion => "1.0.0";
        public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context)
        {
            Logger logger = new LoggerConfiguration() // Create a logger configuration
                .MinimumLevel.Information() // Set a global minimal event level for logger to Information
                .WriteTo.GmodSink(restrictedToMinimumLevel: LogEventLevel.Warning) // Add a game console sink which writes only events of Warning severity level and above
                .CreateLogger();

            logger.Warning("Here is a warning to game console!");
        }

        public void Unload(ILua lua)
        {

        }
    }
}