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


C# ILogger.LogWarning方法代码示例

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


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

示例1: Initialize

        public bool Initialize(ILogger logger)
        {
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            bool success;

            this.conversionToolPath = GetExeToolPath(logger);

            if (this.conversionToolPath == null)
            {
                logger.LogWarning(Resources.CONV_WARN_FailToFindConversionTool);
                success = false;
            }
            else
            {
                Debug.Assert(File.Exists(this.conversionToolPath), "Expecting the code coverage exe to exist. Full name: " + this.conversionToolPath);
                logger.LogDebug(Resources.CONV_DIAG_CommandLineToolInfo, this.conversionToolPath);
                success = true;
            }
            return success;
        }
开发者ID:BrightLight,项目名称:sonar-msbuild-runner,代码行数:24,代码来源:CoverageReportConverter.cs

示例2: RetryRequest

        /// <summary>
        /// Retries every 1 sec for 60 times by default.
        /// </summary>
        /// <param name="retryBlock"></param>
        /// <param name="logger"></param>
        /// <param name="cancellationToken"></param>
        /// <param name="retryCount"></param>
        public static async Task<HttpResponseMessage> RetryRequest(
            Func<Task<HttpResponseMessage>> retryBlock,
            ILogger logger,
            CancellationToken cancellationToken = default(CancellationToken),
            int retryCount = 60)
        {
            for (int retry = 0; retry < retryCount; retry++)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    logger.LogInformation("Failed to connect, retry canceled.");
                    throw new OperationCanceledException("Failed to connect, retry canceled.", cancellationToken);
                }

                try
                {
                    logger.LogWarning("Retry count {retryCount}..", retry + 1);
                    var response = await retryBlock();

                    if (response.StatusCode == HttpStatusCode.ServiceUnavailable)
                    {
                        // Automatically retry on 503. May be application is still booting.
                        logger.LogWarning("Retrying a service unavailable error.");
                        continue;
                    }

                    return response; // Went through successfully
                }
                catch (Exception exception)
                {
                    if (retry == retryCount - 1)
                    {
                        logger.LogError("Failed to connect, retry limit exceeded.", exception);
                        throw;
                    }
                    else
                    {
                        if (exception is HttpRequestException
#if DNX451
                        || exception is System.Net.WebException
#endif
                        )
                        {
                            logger.LogWarning("Failed to complete the request : {0}.", exception.Message);
                            await Task.Delay(1 * 1000); //Wait for a while before retry.
                        }
                    }
                }
            }

            logger.LogInformation("Failed to connect, retry limit exceeded.");
            throw new OperationCanceledException("Failed to connect, retry limit exceeded.");
        }
开发者ID:qiudesong,项目名称:Hosting,代码行数:60,代码来源:RetryHelper.cs

示例3: ComputeVerbosity

        private static LoggerVerbosity ComputeVerbosity(string sonarVerboseValue, string sonarLogValue, ILogger logger)
        {
            if (!String.IsNullOrWhiteSpace(sonarVerboseValue))
            {
                if (sonarVerboseValue.Equals("true", StringComparison.Ordinal))
                {
                    logger.LogDebug(Resources.MSG_SonarVerboseWasSpecified, sonarVerboseValue, LoggerVerbosity.Debug);
                    return LoggerVerbosity.Debug;
                }
                else if (sonarVerboseValue.Equals("false", StringComparison.Ordinal))
                {
                    logger.LogDebug(Resources.MSG_SonarVerboseWasSpecified, sonarVerboseValue, LoggerVerbosity.Info);
                    return LoggerVerbosity.Info;
                }
                else
                {
                    logger.LogWarning(Resources.WARN_SonarVerboseNotBool, sonarVerboseValue);
                }
            }

            if (!String.IsNullOrWhiteSpace(sonarLogValue))
            {
                if (sonarLogValue.Split('|').Any(s => s.Equals(SonarLogDebugValue, StringComparison.Ordinal)))
                {
                    logger.LogDebug(Resources.MSG_SonarLogLevelWasSpecified, sonarLogValue);
                    return LoggerVerbosity.Debug;
                }
            }

            return DefaultLoggingVerbosity;
        }
开发者ID:BrightLight,项目名称:sonar-msbuild-runner,代码行数:31,代码来源:VerbosityCalculator.cs

示例4: Route

 public static void Route(ILogger logger, string msg)
 {
     if (!msg.IsNullOrEmpty())
     {
         if (msg.StartsWith(StartVerbose))
             _isVerboseMode = true;
         else if (msg.StartsWith(StopVerbose))
             _isVerboseMode = false;
         else
         {
             if (msg.StartsWith(Verbose))
                 logger.LogVerbose(msg.Substring(Verbose.Length));
             else if (msg.StartsWith(Success))
                 logger.LogSuccess(msg.Substring(Success.Length));
             else if (msg.StartsWith(Warning))
                 logger.LogWarning(msg.Substring(Warning.Length));
             else if (msg.StartsWith(Error))
                 logger.LogError(msg.Substring(Error.Length));
             else if (msg.StartsWith(Header))
             {
                 _isVerboseMode = false;
                 logger.LogHeader(msg.Substring(Header.Length));
             }
             else if (_isVerboseMode)
                 logger.LogVerbose(msg);
             else
                 logger.LogInfo(msg);
         }
     }
     else
     {
         //logger.LogInfo(msg);
     }
 }
开发者ID:mdavid626,项目名称:triton,代码行数:34,代码来源:LogRouter.cs

示例5: DropDatabase

        public static void DropDatabase(string databaseName, ILogger logger)
        {
            try
            {
                logger.LogInformation("Trying to drop database '{0}'", databaseName);
                using (var conn = new SqlConnection(string.Format(CONNECTION_STRING_FORMAT, "master")))
                {
                    conn.Open();

                    var cmd = conn.CreateCommand();
                    cmd.CommandText = string.Format(@"IF EXISTS (SELECT * FROM sys.databases WHERE name = N'{0}')
                                          BEGIN
                                               ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
                                               DROP DATABASE [{0}];
                                          END", databaseName);
                    cmd.ExecuteNonQuery();

                    logger.LogInformation("Successfully dropped database {0}", databaseName);
                }
            }
            catch (Exception exception)
            {
                //Ignore if there is failure in cleanup.
                logger.LogWarning("Error occurred while dropping database {0}. Exception : {1}", databaseName, exception.ToString());
            }
        }
开发者ID:leloulight,项目名称:MusicStore,代码行数:26,代码来源:DbUtils.cs

示例6: Analyze

        public DependencyAnalyzerResult Analyze(ILogger logger)
        {
            var result = new DependencyAnalyzerResult();

            result.AnalyzedFiles = GetLibrariesAndExecutables().ToArray();

            if (result.AnalyzedFiles.Length <= 0)
            {
                return result;
            }

            result.Assemblies = new Dictionary<string, AssemblyReferenceInfo>(StringComparer.OrdinalIgnoreCase);
            foreach (var fileInfo in result.AnalyzedFiles.OrderBy(asm => asm.Name))
            {
                logger.LogMessage(string.Format("Checking file {0}", fileInfo.Name));
                Assembly assembly;
                try
                {
                    if (!fileInfo.IsAssembly())
                    {
                        continue;
                    }
                    assembly = Assembly.ReflectionOnlyLoadFrom(fileInfo.FullName);
                }
                catch (Exception ex)
                {
                    logger.LogWarning(string.Format("Failed to load assembly '{0}': {1}", fileInfo.FullName, ex.Message));
                    continue;
                }
                var assemblyReferenceInfo = GetAssemblyReferenceInfo(result.Assemblies, assembly.GetName());
                assemblyReferenceInfo.ReflectionOnlyAssembly = assembly;
                assemblyReferenceInfo.AssemblySource = AssemblySource.Local;
                foreach (var referencedAssembly in assembly.GetReferencedAssemblies())
                {
                    var referencedAssemblyReferenceInfo = GetAssemblyReferenceInfo(result.Assemblies, referencedAssembly); ;
                    assemblyReferenceInfo.AddReference(referencedAssemblyReferenceInfo);
                    referencedAssemblyReferenceInfo.AddReferencedBy(assemblyReferenceInfo);
                }
            }

            foreach (var assembly in result.Assemblies.Values)
            {
                if (assembly.ReflectionOnlyAssembly != null)
                {
                    continue;
                }
                logger.LogMessage(string.Format("Checking reference {0}", assembly.AssemblyName.Name));
                try
                {
                    assembly.ReflectionOnlyAssembly = Assembly.ReflectionOnlyLoad(assembly.AssemblyName.FullName);
                    assembly.AssemblySource = assembly.ReflectionOnlyAssembly.GlobalAssemblyCache ? AssemblySource.GAC : AssemblySource.Unknown;
                }
                catch (Exception ex)
                {
                    // TODO: Show message?
                }
            }
            return result;
        }
开发者ID:mikehadlow,项目名称:AsmSpy,代码行数:59,代码来源:DependencyAnalyzer.cs

示例7: ElasticSearchDataHelper

        public ElasticSearchDataHelper(IConfigurationElasticClientSettings elasticClientSettings, ILoggerFactory loggerFactory)
        {
            log = loggerFactory.CreateLogger<ElasticSearchDataHelper>();
            log.LogWarning("Inside ElasticSearchDataHelper");
          
            itemCount = elasticClientSettings.DefaultItemCount;
            client = elasticClientSettings.Client;

            log.LogInformation(DateTime.Now.ToLongTimeString() + "connstring=" + elasticClientSettings.ConnectionString);
        }
开发者ID:flakio,项目名称:catalog,代码行数:10,代码来源:ElasticSearchDataHelper.cs

示例8: BootstrapperFactory

 public BootstrapperFactory(ILogger logger,IServiceCollection services,object context,TimeSpan sessionTimeoutInterval)
 {
     this._logger = logger;
     this._services = services;
     if (context == null)
     {
         _logger.LogWarning("Environment variable is not properly set. Please specify directly using ASPNET_ENV={environmentName}. Attempting to use ASPNET_ENV=Development by default.");
         context = "Development";
     }
     this._context = context;
     _sessionTimeout = sessionTimeoutInterval;
 }
开发者ID:anton-gorbikov,项目名称:Bookshelf,代码行数:12,代码来源:BootstrapperFactory.cs

示例9: VerifyExitCode

        static void VerifyExitCode(this Process command, ProcessResult result, ResultExpectation resultExpectation, ILogger logger)
        {
            if (result.ExitCode == SuccessExitCode)
                return;

            string message = string.Format("Process \"{0}\" failed, exit code {1}. All output: {2}",
                command.Options.CommandLine, result.ExitCode, result.AllOutput);

            if (resultExpectation == ResultExpectation.MustNotFail)
                throw new Exception(message);

            logger.LogWarning(message);
        }
开发者ID:tomaskovarik,项目名称:chalk,代码行数:13,代码来源:ProcessExtensions.cs

示例10: Retry

        public static void Retry(Action retryBlock, ILogger logger, int retryCount = 7)
        {
            for (int retry = 0; retry < retryCount; retry++)
            {
                try
                {
                    logger.LogWarning("Retry count {retryCount}..", retry + 1);
                    retryBlock();
                    break; //Went through successfully
                }
                catch (AggregateException exception)
                {
                    if (exception.InnerException is HttpRequestException
#if DNX451
                        || exception.InnerException is WebException
#endif
                        )
                    {
                        logger.LogWarning("Failed to complete the request.", exception);
                        Thread.Sleep(7 * 1000); //Wait for a while before retry.
                    }
                }
            }
        }
开发者ID:alexandreana,项目名称:MusicStore,代码行数:24,代码来源:Helpers.cs

示例11: VersionProviderFactory

 public VersionProviderFactory(
     ILogger<VersionProviderFactory> logger,
     IEnumerable<IVersionProvider> versionProviders = null)
 {
     if (logger == null) { throw new ArgumentNullException(nameof(logger)); }
     log = logger;
     if (versionProviders != null)
     {
         VersionProviders = versionProviders;
     }
     else
     {
         VersionProviders = new List<IVersionProvider>();
         log.LogWarning("IEnumerable<IVersionProvider> was null, make sure any needed IVersionProviders have been added to DI");
     }
 }
开发者ID:ReinhardHsu,项目名称:cloudscribe,代码行数:16,代码来源:VersionProviderFactory.cs

示例12: OpenNuspecStreamFromNupkgAsync

        internal static async Task<Stream> OpenNuspecStreamFromNupkgAsync(
            string id,
            Task<Stream> openNupkgStreamAsync,
            ILogger report)
        {
            using (var nupkgStream = await openNupkgStreamAsync)
            {
                try
                {
                    using (var archive = new ZipArchive(nupkgStream, ZipArchiveMode.Read, leaveOpen: true))
                    {
                        var entry = archive.GetEntryOrdinalIgnoreCase(id + ".nuspec");
                        using (var entryStream = entry.Open())
                        {
                            var nuspecStream = new MemoryStream((int)entry.Length);
#if DNXCORE50
    // System.IO.Compression.DeflateStream throws exception when multiple
    // async readers/writers are working on a single instance of it
                            entryStream.CopyTo(nuspecStream);
#else
                            await entryStream.CopyToAsync(nuspecStream);
#endif
                            nuspecStream.Seek(0, SeekOrigin.Begin);
                            return nuspecStream;
                        }
                    }
                }
                catch (InvalidDataException)
                {
                    var fileStream = nupkgStream as FileStream;
                    if (fileStream != null)
                    {
                        report.LogWarning($"The ZIP archive {fileStream.Name.Yellow().Bold()} is corrupt");
                    }
                    throw;
                }
            }
        }
开发者ID:eerhardt,项目名称:NuGet3,代码行数:38,代码来源:PackageUtilities.cs

示例13: DiaResolver

        internal DiaResolver(string binary, string pathExtension, ILogger logger, bool debugMode)
        {
            _binary = binary;
            _logger = logger;
            _debugMode = debugMode;

            string pdb = FindPdbFile(binary, pathExtension);
            if (pdb == null)
            {
                _logger.LogWarning($"Couldn't find the .pdb file of file '{binary}'. You will not get any source locations for your tests.");
                return;
            }

            if (!TryCreateDiaInstance(Dia140) && !TryCreateDiaInstance(Dia120) && !TryCreateDiaInstance(Dia110))
            {
                _logger.LogError("Couldn't find the msdia.dll to parse *.pdb files. You will not get any source locations for your tests.");
                return;
            }

            if (_debugMode)
                _logger.LogInfo($"Parsing pdb file \"{pdb}\"");

            _fileStream = File.Open(pdb, FileMode.Open, FileAccess.Read, FileShare.Read);
            _diaDataSource.loadDataFromIStream(new DiaMemoryStream(_fileStream));

            dynamic diaSession110Or140;
            _diaDataSource.openSession(out diaSession110Or140);
            _diaSession = new DiaSessionAdapter(diaSession110Or140);
        }
开发者ID:csoltenborn,项目名称:GoogleTestAdapter,代码行数:29,代码来源:DiaResolver.cs

示例14: TryGetPhase

        private static bool TryGetPhase(int originalArgCount, IEnumerable<ArgumentInstance> arguments, ILogger logger, out AnalysisPhase phase)
        {
            // The command line parser will already have checked for duplicates
            ArgumentInstance argumentInstance;
            bool hasBeginVerb = ArgumentInstance.TryGetArgument(BeginId, arguments, out argumentInstance);
            bool hasEndVerb = ArgumentInstance.TryGetArgument(EndId, arguments, out argumentInstance);

            if (hasBeginVerb && hasEndVerb) // both
            {
                phase = AnalysisPhase.Unspecified;
                logger.LogError(Resources.ERROR_CmdLine_BothBeginAndEndSupplied);
            }
            else if (!hasBeginVerb && !hasEndVerb) // neither
            {
                // Backwards compatibility - decide the phase based on the number of arguments passed
                phase = originalArgCount == 0 ? AnalysisPhase.PostProcessing : AnalysisPhase.PreProcessing;
                logger.LogWarning(Resources.WARN_CmdLine_v09_Compat);
            }
            else // begin or end
            {
                phase = hasBeginVerb ? AnalysisPhase.PreProcessing : AnalysisPhase.PostProcessing;
            }

            return phase != AnalysisPhase.Unspecified;
        }
开发者ID:nilleb,项目名称:sonar-msbuild-runner,代码行数:25,代码来源:ArgumentProcessor.cs

示例15: StartSelfHost

        private static Process StartSelfHost(StartParameters startParameters, ILogger logger)
        {
            var commandName = startParameters.ServerType == ServerType.WebListener ? "web" : "kestrel";
            logger.LogInformation("Executing dnx.exe --appbase {appPath} \"Microsoft.Framework.ApplicationHost\" {command}", startParameters.ApplicationPath, commandName);

            var startInfo = new ProcessStartInfo
            {
                FileName = "dnx.exe",
                Arguments = string.Format("--appbase \"{0}\" \"Microsoft.Framework.ApplicationHost\" {1}", startParameters.ApplicationPath, commandName),
                UseShellExecute = true,
                CreateNoWindow = true
            };

            var hostProcess = Process.Start(startInfo);
            //Sometimes reading MainModule returns null if called immediately after starting process.
            Thread.Sleep(1 * 1000);

            if (hostProcess.HasExited)
            {
                logger.LogError("Host process {processName} exited with code {exitCode} or failed to start.", startInfo.FileName, hostProcess.ExitCode);
                throw new Exception("Failed to start host");
            }

            try
            {
                logger.LogInformation("Started {fileName}. Process Id : {processId}", hostProcess.MainModule.FileName, hostProcess.Id);
            }
            catch (Win32Exception win32Exception)
            {
                logger.LogWarning("Cannot access 64 bit modules from a 32 bit process. Failed with following message.", win32Exception);
            }

            return hostProcess;
        }
开发者ID:alexandreana,项目名称:MusicStore,代码行数:34,代码来源:DeploymentUtility.cs


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