Util.CustomSerilog 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Util.CustomSerilog --version 1.0.0                
NuGet\Install-Package Util.CustomSerilog -Version 1.0.0                
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.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Util.CustomSerilog --version 1.0.0                
#r "nuget: Util.CustomSerilog, 1.0.0"                
#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.0.0

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

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,
    "Path": "C:\\temp\\logs\\app.log",
    "LogAsJson": true,
    "MinLogLevel": "Verbose",
    "FileSizeLimitBytes": 10000000,
    "RetainedFileCountLimit": 99
  },
  "AllowedHosts": "*"
}

License

MIT

There are no supported framework assets in this 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.

Добавлено логирование в консоль