Glodon.IM.Logger
1.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Glodon.IM.Logger --version 1.0.3
NuGet\Install-Package Glodon.IM.Logger -Version 1.0.3
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.3" />
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.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Glodon.IM.Logger, 1.0.3"
#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.3 // Install Glodon.IM.Logger as a Cake Tool #tool nuget:?package=Glodon.IM.Logger&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
组件功能说明:
扩展 .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",
"RabbitMQ": {
"HostName": "127.0.0.1",
"Port": 5672,
"UserName": "guest",
"Password": "guest",
"ExChange": "log",
"RoutingKey": "log",
"Queue": "log",
"IsDurable": true,
"RetryInterval": 10,
"AutoPushSelfException": false
}
}
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 | Versions 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.
-
.NETCoreApp 2.1
- Microsoft.AspNetCore.Http.Abstractions (>= 2.1.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.1.1)
- Microsoft.Extensions.Logging (>= 2.1.1)
- Microsoft.Extensions.Logging.Configuration (>= 2.1.1)
- Microsoft.Extensions.Options (>= 2.1.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 2.1.1)
- RabbitMQ.Client (>= 5.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.