Serilog update

12 views
Skip to first unread message

Janus C. H. Knudsen

unread,
Aug 13, 2016, 8:07:21 AM8/13/16
to XSockets.NET Developer forum
Hi Uffe

Would it be possible for you to upgrade XSockets Server to use the newest version of Serilog, it seems that there are some constraints involved so it is impossible to do by one self.

Cheers
Janus

Ulf Björklund

unread,
Aug 14, 2016, 4:01:25 AM8/14/16
to XSockets.NET Developer forum
Hi.

You can replace the custom logger with any other logger, unfortunatelly the only logger that cant be added as a "new" logger is Serilog since the XSockets packages has a dependency on that one.
The new Serilog has some breaking changes (hence the new major version) which means that we have to update a few things in the default logger to be able to let you update to Serilog 2.*

We will probably remove the dependency to Serilog on nuget and just have the assembly embedded so that you can replace Serilog in the future in any way you like. The same thing with Newtonsoft!

We can provide a new package within a few days I hope.

Regards, Uffe

Ulf Björklund

unread,
Aug 14, 2016, 4:27:46 AM8/14/16
to XSockets.NET Developer forum
Hi again Janus.

I tried to upgrade without a new build using the plugin framework of XSockets and it seems to work.
Here is what I did.

  1. Created a new console app and installed XSockets.Server
  2. Removed the assemblies for Serilog and the XSockets.Logger assembly.
  3. Created a new class library for the new serilog.
  4. Installed Serilog and Serilog.Sinks.Literate into the new class library
  5. Installed XSockets.Core into the new library as well. This is to get the interface for IXLogger available.
  6. Added a new class for logging by implementing IXLogger interface for Serilog.
namespace NewLogger
{
    using System;
    using Serilog;
    using XSockets.Core.Common.Utility.Logging;
    using Serilog.Core;

    public class NewSerilog : IXLogger
    {
        private LoggingLevelSwitch levelSwitch;
        public NewSerilog()
        {
            levelSwitch = new LoggingLevelSwitch(Serilog.Events.LogEventLevel.Information);
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.ControlledBy(levelSwitch)                
                .WriteTo.LiterateConsole()                
                .CreateLogger();
        }

        public void Debug(string template, params object[] parmeters)
        {
            Log.Debug(template, parmeters);
        }

        public void Debug(Exception ex, string template, params object[] parmeters)
        {
            Log.Debug(ex, template, parmeters);
        }

        public void Error(string template, params object[] parmeters)
        {
            Log.Error(template, parmeters);
        }

        public void Error(Exception ex, string template, params object[] parmeters)
        {
            Log.Error(ex,template, parmeters);
        }

        public void Fatal(string template, params object[] parmeters)
        {
            Log.Fatal(template, parmeters);
        }

        public void Fatal(Exception ex, string template, params object[] parmeters)
        {
            Log.Fatal(ex, template, parmeters);
        }

        public void Information(string template, params object[] parmeters)
        {
            Log.Information(template, parmeters);
        }

        public void Information(Exception ex, string template, params object[] parmeters)
        {
            Log.Information(ex,template, parmeters);
        }

        public bool LevelEnabled(LogEventLevel level)
        {
            return Log.IsEnabled((Serilog.Events.LogEventLevel)level);
        }

        public void SetEventLevel(LogEventLevel level)
        {
            this.levelSwitch.MinimumLevel = (Serilog.Events.LogEventLevel)level;            
        }

        public void Verbose(string template, params object[] parmeters)
        {
            Log.Verbose(template, parmeters);
        }

        public void Verbose(Exception ex, string template, params object[] parmeters)
        {
            Log.Verbose(ex, template, parmeters);
        }

        public void Warning(string template, params object[] parmeters)
        {
            Log.Warning(template, parmeters);
        }

        public void Warning(Exception ex, string template, params object[] parmeters)
        {
            Log.Warning(ex, template, parmeters);
        }
    }
}

Then I referenced the new logger project in my XSockets server project.

When I start the server the new Serilog is used. See below.


Regards, Uffe




Reply all
Reply to author
Forward
0 new messages