Util.CustomSerilog 1.2.2

dotnet add package Util.CustomSerilog --version 1.2.2                
NuGet\Install-Package Util.CustomSerilog -Version 1.2.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Util.CustomSerilog" Version="1.2.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Util.CustomSerilog --version 1.2.2                
#r "nuget: Util.CustomSerilog, 1.2.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Util.CustomSerilog as a Cake Addin
#addin nuget:?package=Util.CustomSerilog&version=1.2.2

// Install Util.CustomSerilog as a Cake Tool
#tool nuget:?package=Util.CustomSerilog&version=1.2.2                

CustomSerilog

Библиотека для логирования

Build Status

Инициализация

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using CustomSerilog;
using CustomSerilog.Logger;
using System.Reflection;
using System;
using System.Net;

public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

public void ConfigureServices(IServiceCollection services)
        {
            services.AddCustomSerilog(Configuration);
        }
        
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
        //Передаём имя приложения, версию сборки, имя хоста, ip адрес хоста
            app.UseLogger("Test_app",
                typeof(Startup).Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version,
                Environment.MachineName,
                string.Join<IPAddress>(',', Dns.GetHostAddresses(Environment.MachineName)));
        }

Пример пример использование в контроллере

using CustomSerilog.Logger;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;

namespace WebApplication3.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string [] Summaries = new []
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger _logger;

        public WeatherForecastController(ILogger logger)
        {
            _logger = logger;
        }

        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            _logger.Information("Test_Message");
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries [rng.Next(Summaries.Length)]
            })
            .ToArray();
        }
    }
}

Пример конфигурационного файла

{
  "LoggerOptions": {
    "LogToFile": true,
    "LogToElasticsearch": false,
    "UrlElasticsearch": "http://localhost:9200",
    "Path": "C:\\temp\\logs\\app.log",
    "LogAsJson": true,
    "MinLogLevel": "Verbose",
    "FileSizeLimitBytes": 10000000,
    "RetainedFileCountLimit": 99
  },
  "AllowedHosts": "*"
}

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Добавлена возможность записи в ElasticSearch