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


C# ILogger.WriteError方法代码示例

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


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

示例1: Build

        public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
        {
            logger.WriteLineInfo($"BuildScript: {generateResult.ArtifactsPaths.BuildScriptFilePath}");

            var syntaxTree = CSharpSyntaxTree.ParseText(File.ReadAllText(generateResult.ArtifactsPaths.ProgramCodePath));

            var compilationOptions = new CSharpCompilationOptions(
                 outputKind: OutputKind.ConsoleApplication,
                 optimizationLevel: OptimizationLevel.Release,
                 allowUnsafe: true,
                 platform: GetPlatform(benchmark.Job.Platform),
                 deterministic: true);

            var references = RoslynGenerator
                .GetAllReferences(benchmark)
                .Select(assembly => AssemblyMetadata.CreateFromFile(assembly.Location))
                .Concat(FrameworkAssembliesMetadata.Value)
                .Distinct()
                .Select(uniqueMetadata => uniqueMetadata.GetReference());

            var compilation = CSharpCompilation
                .Create(assemblyName: Path.GetFileName(generateResult.ArtifactsPaths.ExecutablePath))
                .AddSyntaxTrees(syntaxTree)
                .WithOptions(compilationOptions)
                .AddReferences(references);

            using (var executable = File.Create(generateResult.ArtifactsPaths.ExecutablePath))
            {
                var emitResult = compilation.Emit(executable);

                if(emitResult.Success)
                {
                    return BuildResult.Success(generateResult);
                }

                foreach (var diagnostic in emitResult.Diagnostics
                    .Where(diagnostic => diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error))
                {
                    logger.WriteError($"{diagnostic.Id}: {diagnostic.GetMessage()}");
                }

                return BuildResult.Failure(generateResult);
            }
        }
开发者ID:yuleyule66,项目名称:BenchmarkDotNet,代码行数:44,代码来源:RoslynBuilder.cs

示例2: RestService

        public RestService(INancyBootstrapper bootstrapper, IServiceConfig config, ILogger logger, ShortlistQueryRepository shortlistQueryRepository)
        {
            if (bootstrapper == null) { throw new ArgumentNullException(nameof(bootstrapper)); }
            if (config == null) { throw new ArgumentNullException(nameof(config)); }
            if (logger == null) { throw new ArgumentNullException(nameof(logger)); }
            if (shortlistQueryRepository == null) { throw new ArgumentNullException(nameof(shortlistQueryRepository)); }

            _shortlistQueryRepository = shortlistQueryRepository;
            var nancyConfig = new HostConfiguration();
            nancyConfig.UrlReservations.CreateAutomatically = true;

            _nancyService = new NancyHost(bootstrapper, nancyConfig, new Uri(config.RestUrl));
            nancyConfig.UnhandledExceptionCallback = (exception) =>
            {
                var message = String.Format("Uncaught exception: {0}", exception.Message);
                logger.WriteError(message);
            };
            if (config.QueueConsumer)
            {
                SetupEventQueueListener(config, logger);
            }
        }
开发者ID:luukwullink,项目名称:Wul.Link,代码行数:22,代码来源:RestService.cs

示例3: ExecuteImpl

        private ExecuteResult ExecuteImpl(Process process, string exeName, Benchmark benchmark, ILogger logger, IDiagnoser compositeDiagnoser = null)
        {
            process.PriorityClass = ProcessPriorityClass.High;
            if (!benchmark.Job.Affinity.IsAuto)
                process.ProcessorAffinity = new IntPtr(benchmark.Job.Affinity.Value);

            var lines = new List<string>();
            string line;
            while ((line = process.StandardOutput.ReadLine()) != null)
            {
                logger?.WriteLine(line);
                if (!line.StartsWith("//") && !string.IsNullOrEmpty(line))
                    lines.Add(line);

                if (compositeDiagnoser == null)
                    continue;

                // This is important so the Diagnoser can know the [Benchmark] methods will have run and (e.g.) it can do a Memory Dump
                if (diagnosticsAlreadyRun == false && line.StartsWith(IterationMode.MainWarmup.ToString()))
                {
                    try
                    {
                        compositeDiagnoser.AfterBenchmarkHasRun(benchmark, process);
                    }
                    finally
                    {
                        // Always set this, even if something went wrong, otherwise we will try on every run of a benchmark batch
                        diagnosticsAlreadyRun = true;
                    }
                }
            }

            if (process.HasExited && process.ExitCode != 0)
            {
                if (logger != null)
                {
                    logger.WriteError(
                        $"Something bad happened during the execution of {exeName}. Try to run the benchmark again using an AnyCPU application\n");
                }
                else
                {
                    if (exeName.ToLowerInvariant() == "msbuild")
                        Console.WriteLine("Build failed");
                }
                return new ExecuteResult(true, new string[0]);
            }

            return new ExecuteResult(true, lines);
        }
开发者ID:bestwpw,项目名称:BenchmarkDotNet,代码行数:49,代码来源:ClassicExecutor.cs


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