本文整理汇总了C#中ILogger.IsEnabled方法的典型用法代码示例。如果您正苦于以下问题:C# ILogger.IsEnabled方法的具体用法?C# ILogger.IsEnabled怎么用?C# ILogger.IsEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILogger
的用法示例。
在下文中一共展示了ILogger.IsEnabled方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefaultTypeConvertibleService
public DefaultTypeConvertibleService(IEnumerable<ITypeConvertibleProvider> providers, ILogger<DefaultTypeConvertibleService> logger)
{
_logger = logger;
providers = providers.ToArray();
if (_logger.IsEnabled(LogLevel.Debug))
_logger.Debug($"发现了以下类型转换提供程序:{string.Join(",", providers.Select(p => p.ToString()))}。");
_converters = providers.SelectMany(p => p.GetConverters()).ToArray();
}
示例2: FilteredLog
private static void FilteredLog(ILogger logger, LogLevel level, string message, Exception exception = null, Customer customer = null)
{
//don't log thread abort exception
if (exception is System.Threading.ThreadAbortException)
return;
if (logger.IsEnabled(level))
{
string fullMessage = exception == null ? string.Empty : exception.ToString();
logger.InsertLog(level, message, fullMessage, customer);
}
}
示例3: FilteredLog
private static void FilteredLog(ILogger logger, LogLevel level, string message, Exception exception = null,
User user = null)
{
//No se guarda el registro cuando es de un hilo de una excepcion de abort
if (exception is ThreadAbortException)
return;
if (logger.IsEnabled(level))
{
var fullMessage = exception == null ? string.Empty : exception.ToString();
logger.InsertLog(level, message, fullMessage, user);
}
}
示例4: FilteredLog
private static void FilteredLog(ILogger logger, LogLevel level, string message,
Exception exception = null, Customer customer = null, bool stopException = true)
{
// không log thông điệp khi ngoại lệ là ThreadAbortException
if (exception is ThreadAbortException) return;
try
{
if (logger.IsEnabled(level)) // nếu cho phép ghi log với kiểu level
{
string fullMessage = exception == null ? string.Empty : exception.ToString();
logger.InsertLog(level, message, fullMessage, customer);
}
}
catch (Exception)
{
if (!stopException) throw;
}
}
示例5: FilteredLog
private static void FilteredLog(ILogger logger, LogLevel level, Exception exception, string format, object[] objects) {
if (logger.IsEnabled(level)) {
logger.Log(level, exception, format, objects);
}
}
示例6: ExecuteAsync
public override async Task ExecuteAsync(
IRelationalConnection connection,
ILogger logger,
CancellationToken cancellationToken = default(CancellationToken))
{
Check.NotNull(connection, nameof(connection));
Check.NotNull(logger, nameof(logger));
var commandText = GetCommandText();
using (var storeCommand = CreateStoreCommand(commandText, connection))
{
if (logger.IsEnabled(LogLevel.Verbose))
{
logger.LogCommand(storeCommand);
}
try
{
using (var reader = await storeCommand.ExecuteReaderAsync(cancellationToken))
{
await ConsumeAsync(reader, cancellationToken);
}
}
catch (DbUpdateException)
{
throw;
}
catch (Exception ex)
{
throw new DbUpdateException(RelationalStrings.UpdateStoreException, ex);
}
}
}
示例7: Execute
public override void Execute(
IRelationalConnection connection,
ILogger logger)
{
Check.NotNull(connection, nameof(connection));
Check.NotNull(logger, nameof(logger));
var commandText = GetCommandText();
using (var storeCommand = CreateStoreCommand(commandText, connection))
{
if (logger.IsEnabled(LogLevel.Verbose))
{
logger.LogCommand(storeCommand);
}
try
{
using (var reader = storeCommand.ExecuteReader())
{
Consume(reader);
}
}
catch (DbUpdateException)
{
throw;
}
catch (Exception ex)
{
throw new DbUpdateException(RelationalStrings.UpdateStoreException, ex);
}
}
}
示例8: IsLogLevelEnabledCore
private static bool IsLogLevelEnabledCore(ILogger logger, LogLevel level)
{
return (logger != null && logger.IsEnabled(level));
}
示例9: ExecuteAsync
public override async Task<int> ExecuteAsync(
RelationalTransaction transaction,
RelationalTypeMapper typeMapper,
DbContext context,
ILogger logger,
CancellationToken cancellationToken = default(CancellationToken))
{
Check.NotNull(transaction, nameof(transaction));
Check.NotNull(typeMapper, nameof(typeMapper));
Check.NotNull(context, nameof(context));
Check.NotNull(logger, nameof(logger));
var commandText = GetCommandText();
Debug.Assert(ResultSetEnds.Count == ModificationCommands.Count);
var commandIndex = 0;
using (var storeCommand = CreateStoreCommand(commandText, transaction.DbTransaction, typeMapper, transaction.Connection?.CommandTimeout))
{
if (logger.IsEnabled(LogLevel.Verbose))
{
logger.LogCommand(storeCommand);
}
try
{
using (var reader = await storeCommand.ExecuteReaderAsync(cancellationToken).WithCurrentCulture())
{
var actualResultSetCount = 0;
do
{
commandIndex = ModificationCommands[commandIndex].RequiresResultPropagation
? await ConsumeResultSetWithPropagationAsync(commandIndex, reader, context, cancellationToken)
.WithCurrentCulture()
: await ConsumeResultSetWithoutPropagationAsync(commandIndex, reader, context, cancellationToken)
.WithCurrentCulture();
actualResultSetCount++;
}
while (commandIndex < ResultSetEnds.Count
&& await reader.NextResultAsync(cancellationToken).WithCurrentCulture());
Debug.Assert(commandIndex == ModificationCommands.Count, "Expected " + ModificationCommands.Count + " results, got " + commandIndex);
#if DEBUG
var expectedResultSetCount = 1 + ResultSetEnds.Count(e => e);
expectedResultSetCount += ResultSetEnds[ResultSetEnds.Count - 1] ? -1 : 0;
Debug.Assert(actualResultSetCount == expectedResultSetCount, "Expected " + expectedResultSetCount + " result sets, got " + actualResultSetCount);
#endif
}
}
catch (DbUpdateException)
{
throw;
}
catch (Exception ex)
{
throw new DbUpdateException(
Strings.UpdateStoreException,
context,
ex,
commandIndex < ModificationCommands.Count ? ModificationCommands[commandIndex].Entries : new InternalEntityEntry[0]);
}
}
return commandIndex;
}
示例10: FilteredLog
private static void FilteredLog(ILogger logger, LogLevel level, Exception exception, Func<string> message)
{
if (logger.IsEnabled(level))
logger.Log(level, exception, message == null ? null : message());
}
示例11: FilteredLog
private static void FilteredLog(ILogger logger, LogLevel level, string category, string format, object[] objects)
{
if (logger.IsEnabled(level))
{
logger.Log(level, category, format, objects);
}
}