Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加设置日志级别方法 #18

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Logging;
using System;

namespace RabbitMQ.EventBus.AspNetCore.Configurations
{
Expand Down Expand Up @@ -46,5 +47,13 @@ public void RetryOnFailure(TimeSpan maxRetryDelay)
{
Configuration.ConsumerFailRetryInterval = maxRetryDelay;
}
/// <summary>
/// 设置日志级别
/// </summary>
/// <param name="level">日志级别</param>
public void AddLogging(LogLevel level)
{
ILoggerConfig.Level = level;
}
}
}
17 changes: 15 additions & 2 deletions src/RabbitMQ.EventBus.AspNetCore/Extensions/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

namespace Microsoft.Extensions.Logging
{
/// <summary>
///
/// </summary>
static class ILoggerConfig
{
/// <summary>
///
/// </summary>
public static LogLevel Level { get; set; } = LogLevel.Information;
}
/// <summary>
///
/// </summary>
public static class LoggerExtensions
{
private static readonly Action<ILogger, string, Exception> _informationRequested;
private static readonly Action<ILogger, string, Exception> _informationRequested = null;
static LoggerExtensions()
{
_informationRequested = LoggerMessage.Define<string>(LogLevel.Warning, new EventId(1, nameof(Information)), "{LogContent}");
}
/// <summary>
///
Expand All @@ -19,6 +28,10 @@ static LoggerExtensions()
/// <param name="LogContent"></param>
public static void Information(this ILogger logger, string LogContent)
{
if (_informationRequested == null)
{
LoggerMessage.Define<string>(ILoggerConfig.Level, new EventId(1, nameof(Information)), "{LogContent}");
}
_informationRequested(logger, LogContent, null);
}
}
Expand Down