本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}