当前位置: 首页>>代码示例>>C#>>正文


C# ILogger.LogCommand方法代码示例

本文整理汇总了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);
                }
            }
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:33,代码来源:ReaderModificationCommandBatch.cs

示例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);
                }
            }
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:34,代码来源:ReaderModificationCommandBatch.cs

示例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;
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:66,代码来源:ReaderModificationCommandBatch.cs


注:本文中的ILogger.LogCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。