我可以写SimpleInjectors诊断结果的日志文件? [英] Can I write the results of SimpleInjectors diagnostics to a log file?

查看:260
本文介绍了我可以写SimpleInjectors诊断结果的日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用SimpleInjector我称之为 container.Verify()在我的配置结束,并获得在的的文档。我想这些信息写入日志文件。有没有一种方法访问它编程还是有办法钩记录仪或追踪到SimpleInjector?

Using SimpleInjector I call container.Verify() at the end of my configuration, and get the diagnostics information in the debugger as described in the documentation. I would like to write that information to a log file. Is there a way access it programmatically or a way hook a logger or tracer into SimpleInjector?

推荐答案

简单的喷油器2.4中包含的诊断API (SimpleInjector.Diagnostics.dll),让您查询容器诊断警告。使用此API,你可以写集成测试,可以自动检查配置诊断警告:

Simple Injector 2.4 contains a diagnostic API (SimpleInjector.Diagnostics.dll) that allow you to query the container for diagnostic warnings. Using this API you can write integration tests that automatically check the configuration for diagnostic warnings:

// using SimpleInjector.Diagnostics;

[TestMethod]
public void Container_Always_ContainsNoDiagnosticWarnings()
{
    // Arrange
    var container = Bootstrapper.GetInitializedContainer();

    container.Verify();

    // Assert
    var results = Analyzer.Analyze(container);

    Assert.IsFalse(results.Any(), Environment.NewLine +
        string.Join(Environment.NewLine,
            from result in results
            select result.Description));
}

当然,你也可以写一个文件:

Of course, you can also write this to a file:

var results = Analyzer.Analyze(container);

File.WriteAllLines("c:\\diagnostic.txt", results.Select(r => r.Description));

这篇关于我可以写SimpleInjectors诊断结果的日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆