Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to inject Xunit Logger #5

Open
matiassilioni opened this issue Jan 15, 2019 · 0 comments
Open

how to inject Xunit Logger #5

matiassilioni opened this issue Jan 15, 2019 · 0 comments

Comments

@matiassilioni
Copy link

Hi, Wanted to inject ITestOutputHelper outputHelper (received in test class constructor) in order to write logs to xuint output, so I need this instance to configure my serilog logger sink.

Don't know how to do it from the static method, since it's executed before my constructor

serviceRegistry.Register<Serilog.ILogger>(factory =>
{
const string logTemplate =
"[{Timestamp:HH:mm:ss.fff%K} | {SourceContext}] | [{Level:u3}]{NewLine}{Message:lj}{NewLine}{Exception}";
var logger = new Serilog.LoggerConfiguration()
.MinimumLevel.Is(LogEventLevel.Error)
.Enrich.FromLogContext()
.WriteTo.Trace(outputTemplate: logTemplate)
.WriteTo.Console(outputTemplate: logTemplate)
.WriteTo.TestOutput(factory.GetInstance(),restrictedToMinimumLevel:LogEventLevel.Verbose, outputTemplate:logTemplate)
.CreateLogger();
return logger;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant