Glodon.IM.Logger 1.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package Glodon.IM.Logger --version 1.0.5                
NuGet\Install-Package Glodon.IM.Logger -Version 1.0.5                
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="Glodon.IM.Logger" Version="1.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Glodon.IM.Logger --version 1.0.5                
#r "nuget: Glodon.IM.Logger, 1.0.5"                
#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 Glodon.IM.Logger as a Cake Addin
#addin nuget:?package=Glodon.IM.Logger&version=1.0.5

// Install Glodon.IM.Logger as a Cake Tool
#tool nuget:?package=Glodon.IM.Logger&version=1.0.5                

组件功能说明:

扩展 .Net Core 内置的日志记录功能,提供将日志格式化输出到RabbitMQ。组件支持日志作用域记录、日志最小级别拦截、日志类别筛选、从appseting.json读取配置或手动设置配置、支持appseting.json配置变更后自动应用更新等实用功能。

组件内部只依赖于RabbitMQ Client SDK,再无其他第三方依赖。内部实现了自动重连、自动检测、内部异常自动上报等功能。

Nuget 安装

Install-Package Glodon.IM.Logger -Version 1.0.3 

引入命名空间

using Glodon.IM.Logger;

Startup.cs

// appseting.json 读取配置
services.AddIMLogger(Configuration.GetSection("Logging"));

//手动配置
//services.AddIMLogger(l =>
//{
//    //手动配置 日志
//    l.IncludeScopes = false;//禁用作用域
//    l.MinLevel = LogLevel.Trace;//日志最小级别,小于该级别的不输出
//}, c =>
//{
//    //手动配置 rabbitmq
//    c.HostName = "";
//    c.Port = 5672;
//    c.UserName = "test2";
//    c.Password = "test2";
//    c.VirtualHost = "/";
//    c.ExChange = "log1";
//    c.IsDurable = true;
//    c.Queue = "log1";
//    c.RoutingKey = "log1";
//});

appsettings.json

"Logging": {
    "LogLevel": {
      "Default": "Information",
      "System": "Error",
      "Microsoft": "Error",
      "Glodon.IM.Logger.Test.Controllers.ValuesController": "Information" //支持过滤类别的设置
    },
    "IncludeScopes": false,
    "MinLevel": "Trace",
    "EnableAsync": true,//启用异步记录
    "ApplicationName":"应用程序名称",
    "RabbitMQ": {
      "HostName": "127.0.0.1",
      "Port": 5672,
      "UserName": "guest",
      "Password": "guest",
      "ExChange": "log",
      "RoutingKey": "log",
      "Queue": "log",
      "IsDurable": true,
      "RetryInterval": 10,
      "EnableBuffer": true //启用缓冲
    }
}

HomeController

[Route("api/[controller]")]
    [ApiController]
    public class HomeController : ControllerBase
    {
        private ILogger _Logger;
        public ValuesController(ILogger<HomeController> logger)
        {
            this._Logger = logger;
        }
        // GET api/values
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            //具有作用域的使用示例
            using (_Logger.BeginScope("测试啦。。"))
            {
                _Logger.LogInformation("LogInformation233333333333");
                _Logger.LogDebug("Debug级别日志");
                _Logger.LogWarning("Warning级别日志。。。");
            }
            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(int id)
        {
            _Logger.LogInformation("Information级别日志");
            _Logger.LogDebug("Debug级别日志");
            _Logger.LogWarning("Warning级别日志。。。");
            return "value";
        }
    }

日志输出格式:

[时间][日志级别][线程id,事件id,事件名称][日志类别][日志作用域]

自定义消息

异常详情

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. 
.NET Core netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
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.

Version Downloads Last updated
1.0.6 1,125 1/29/2019
1.0.5 1,043 1/29/2019
1.0.4 1,056 1/29/2019
1.0.3 1,098 1/22/2019
1.0.2 1,139 1/21/2019
1.0.1 1,234 1/21/2019
1.0.0 1,132 1/18/2019