本文整理汇总了C#中ILogger.LogCommand方法的典型用法代码示例。如果您正苦于以下问题:C# ILogger.LogCommand方法的具体用法?C# ILogger.LogCommand怎么用?C# ILogger.LogCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILogger
的用法示例。
在下文中一共展示了ILogger.LogCommand方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
}
示例2: 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);
}
}
}
示例3: 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;
}