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


C# ILogger.ToInfoLog方法代码示例

本文整理汇总了C#中ILogger.ToInfoLog方法的典型用法代码示例。如果您正苦于以下问题:C# ILogger.ToInfoLog方法的具体用法?C# ILogger.ToInfoLog怎么用?C# ILogger.ToInfoLog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILogger的用法示例。


在下文中一共展示了ILogger.ToInfoLog方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitCoordinator

        async static Task<LockingCoordinator> InitCoordinator(
            IEnumerable<LockingNode> lockingNodes,
            Func<long> timeProvider,
            ILogger logger)
        {
            logger.ToInfoLog("Connecting to the locking nodes...");

            return await LockingCoordinator
                .CreateNewForNodes(lockingNodes, timeProvider, logger)
                .ConfigureAwait(false);
        }
开发者ID:barambani,项目名称:varekai,代码行数:11,代码来源:LockingEngine.cs

示例2: StartAttemptingAcquisition

        async static Task StartAttemptingAcquisition(
            LockingCoordinator lockingCoordinator,
            LockId lockId,
            ILogger logger,
            CancellationTokenSource lockingCancellationSource,
            IObserver<object> observer)
        {
            var holdingLock = false;
            var retryInterval = lockId.CalculateRetryInterval();
            var randomGenerator = new Random(Guid.NewGuid().GetHashCode());

            while (!lockingCancellationSource.IsCancellationRequested && !holdingLock)
            {
                try
                {
                    holdingLock = await lockingCoordinator.TryAcquireLock(lockId).ConfigureAwait(false);

                    if(holdingLock)
                    {
                        logger.ToInfoLog(string.Format("DISTRIBUTED LOCK ACQUIRED for {0}", lockId.Resource));
                    }
                    else
                    {
                        logger.ToDebugLog("Unable to acquire the lock, retrying...");

                        await TaskUtils.SilentlyCanceledDelay(
                            randomGenerator.Next(retryInterval.First(), retryInterval.Second()),
                            lockingCancellationSource.Token)
                        .ConfigureAwait(false);
                    }
                }
                catch (Exception ex)
                {
                    observer.OnError(ex);

                    if(lockingCoordinator != null)
                        await lockingCoordinator
                            .TryReleaseTheLock(lockId)
                            .ConfigureAwait(false);

                    holdingLock = false;
                }
            }
        }
开发者ID:barambani,项目名称:varekai,代码行数:44,代码来源:LockingEngine.cs

示例3: ReleaseLock

        async Task ReleaseLock(
            LockingCoordinator lockingCoordinator,
            LockId lockId,
            ILogger logger,
            CancellationTokenSource lockingCancellationSource,
            IObserver<object> observer)
        {
            try
            {
                if(!lockingCancellationSource.IsCancellationRequested)
                    lockingCancellationSource.Cancel();

                observer.OnNext(new LockReleaseStarted());

                logger.ToInfoLog(string.Format("Releasing the lock on {0}...", _lockId.Resource));

                if(lockingCoordinator != null)
                    await lockingCoordinator
                        .TryReleaseTheLock(lockId)
                        .ConfigureAwait(false);
                
                logger.ToInfoLog(string.Format("DISTRIBUTED LOCK RELEASED for {0}", _lockId.Resource));

                observer.OnNext(new LockReleased());

                lockingCoordinator.Dispose();
            }
            catch (Exception ex)
            {
                observer.OnError(ex);
            }
        }
开发者ID:barambani,项目名称:varekai,代码行数:32,代码来源:LockingEngine.cs

示例4: KeepConfirmingTheLock

        async Task KeepConfirmingTheLock(
            LockingCoordinator lockingCoordinator,
            ILogger logger,
            CancellationTokenSource lockingCancellationSource,
            IObserver<object> observer)
        {
            if (lockingCoordinator == null)
            {
                observer.OnError(new ApplicationException("Trying to confirm lock on a NULL coordinator. Invalid locking engine state. Aborting..."));

                return;
            }

            var acquisitionSignaled = false;
            var holdingLock = true;
            var confirmationInterval = _lockId.CalculateConfirmationIntervalMillis();

            logger.ToInfoLog(string.Format("Entering lock retaining mode for {0}", _lockId.Resource));

            try
            {
                while(!lockingCancellationSource.IsCancellationRequested && holdingLock)
                {
                    holdingLock = await lockingCoordinator
                        .TryConfirmTheLock(_lockId)
                        .ConfigureAwait(false);
                    
                    await TaskUtils
                        .SilentlyCanceledDelay(
                            (int)confirmationInterval,
                            lockingCancellationSource.Token)
                        .ConfigureAwait(false);

                    //  signaling the acquisition here guarantees that during a partition the former
                    //  lock holder have the time to realizes it's not holding the lock anymore
                    if(!acquisitionSignaled)
                    {
                        observer.OnNext(new LockAcquired());
                        acquisitionSignaled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                observer.OnError(ex);
            }

            if (!lockingCancellationSource.IsCancellationRequested)
            {
                logger.ToInfoLog(string.Format("Lock held for {0} lost", _lockId.Resource));

                observer.OnNext(new LockHeldLost());

                await ReleaseLock(lockingCoordinator, _lockId, _logger, lockingCancellationSource, observer).ConfigureAwait(false);
            }
        }
开发者ID:barambani,项目名称:varekai,代码行数:56,代码来源:LockingEngine.cs


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