SimpleGelf.Extensions.Logging 1.0.0

Package SimpleGelf

Install-Package SimpleGelf.Extensions.Logging -Version 1.0.0
dotnet add package SimpleGelf.Extensions.Logging --version 1.0.0
<PackageReference Include="SimpleGelf.Extensions.Logging" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimpleGelf.Extensions.Logging --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

That class example demostrate as to use provider.

The appsettings.json file may config:

"LogConfig": {
"NameFile": "C:\Logs\ApiBIlling\apiLog",
"LogEventLevel": 4,
"FlushToDiskIntervalHour": 24,
"Providers": [ "File", "Console", "Graylog" ]
},
"GelfLoggerConfig": {
"User": "",
"Password": "",
"UsingAuthenticate": false,
"Host": "http://127.0.0.1",
"Port": 12201,
"LogSource": "billing_api",
"HttpTimeoutSeconds": 30,
"ListLogLevel": [ 4, 5 ]
},

public class ApplicationLogging : ILoggingService
{
private static ILoggerFactory _Factory = null;
const string providerConsole = "CONSOLE";
const string providerFile = "FILE";
const string providerGrayLog = "GRAYLOG";

    public ApplicationLogging(ILoggerFactory factory, LogConfig logConfig, GelfLoggerConfig gelfLoggerConfig)
    {
        var hasLoggerConsole = logConfig.Providers.Any(x => x.ToUpper().Equals(providerConsole));
        var hasLoggerFile = logConfig.Providers.Any(x => x.ToUpper().Equals(providerFile));
        var hasLoggerGrayLog = logConfig.Providers.Any(x => x.ToUpper().Equals(providerGrayLog));

        var configLogger = new LoggerConfiguration()
               .MinimumLevel.Override("Microsoft", (LogEventLevel)logConfig.LogEventLevel)
               .Enrich.FromLogContext();

        if (hasLoggerConsole)
            configLogger.WriteTo.Console();
        
        if(hasLoggerFile)
            configLogger.WriteTo.File($"{logConfig.NameFile}.txt",
                                        rollingInterval: RollingInterval.Day,
                                        flushToDiskInterval: new TimeSpan(logConfig.FlushToDiskIntervalHour, 0, 0),
                                        restrictedToMinimumLevel: (LogEventLevel)logConfig.LogEventLevel,
                                        rollOnFileSizeLimit: true);

        Log.Logger = configLogger.CreateLogger();

        if (hasLoggerGrayLog)
            factory.AddSimpleGelf(gelfLoggerConfig);

        _Factory = factory.AddSerilog(Log.Logger);
    }
 
    public ILoggerFactory LoggerFactory
    {
        get
        {
            return _Factory;
        }            
    }
}

That class example demostrate as to use provider.

The appsettings.json file may config:

"LogConfig": {
"NameFile": "C:\Logs\ApiBIlling\apiLog",
"LogEventLevel": 4,
"FlushToDiskIntervalHour": 24,
"Providers": [ "File", "Console", "Graylog" ]
},
"GelfLoggerConfig": {
"User": "",
"Password": "",
"UsingAuthenticate": false,
"Host": "http://127.0.0.1",
"Port": 12201,
"LogSource": "billing_api",
"HttpTimeoutSeconds": 30,
"ListLogLevel": [ 4, 5 ]
},

public class ApplicationLogging : ILoggingService
{
private static ILoggerFactory _Factory = null;
const string providerConsole = "CONSOLE";
const string providerFile = "FILE";
const string providerGrayLog = "GRAYLOG";

    public ApplicationLogging(ILoggerFactory factory, LogConfig logConfig, GelfLoggerConfig gelfLoggerConfig)
    {
        var hasLoggerConsole = logConfig.Providers.Any(x => x.ToUpper().Equals(providerConsole));
        var hasLoggerFile = logConfig.Providers.Any(x => x.ToUpper().Equals(providerFile));
        var hasLoggerGrayLog = logConfig.Providers.Any(x => x.ToUpper().Equals(providerGrayLog));

        var configLogger = new LoggerConfiguration()
               .MinimumLevel.Override("Microsoft", (LogEventLevel)logConfig.LogEventLevel)
               .Enrich.FromLogContext();

        if (hasLoggerConsole)
            configLogger.WriteTo.Console();
        
        if(hasLoggerFile)
            configLogger.WriteTo.File($"{logConfig.NameFile}.txt",
                                        rollingInterval: RollingInterval.Day,
                                        flushToDiskInterval: new TimeSpan(logConfig.FlushToDiskIntervalHour, 0, 0),
                                        restrictedToMinimumLevel: (LogEventLevel)logConfig.LogEventLevel,
                                        rollOnFileSizeLimit: true);

        Log.Logger = configLogger.CreateLogger();

        if (hasLoggerGrayLog)
            factory.AddSimpleGelf(gelfLoggerConfig);

        _Factory = factory.AddSerilog(Log.Logger);
    }
 
    public ILoggerFactory LoggerFactory
    {
        get
        {
            return _Factory;
        }            
    }
}

Release Notes

This is simple extension the .Net Core for using as provider loggin..

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0 580 7/20/2018