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

Skip dependency injection wire up? #1

Closed
pardahlman opened this issue Dec 21, 2018 · 0 comments
Closed

Skip dependency injection wire up? #1

pardahlman opened this issue Dec 21, 2018 · 0 comments

Comments

@pardahlman
Copy link

If all you want to do is configure Microsoft's logger to use Serilog, then you shouldn't have to wire up the container

class Program
{
  static void Main(string[] args)
  {
    Log.Logger = new LoggerConfiguration()
      .Enrich.FromLogContext()
      .WriteTo.Console()
      .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200"))
      {
        AutoRegisterTemplate = true,
        AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6,
        IndexFormat = "zipkin-{0:yyyy.MM.dd}"
      })
      .CreateLogger();

    var loggerFactory = new LoggerFactory(new[] {new SerilogLoggerProvider()});
    var logger = loggerFactory.CreateLogger<Program>();

    using (logger.BeginScope("{@scope}", new { value1 = "A value", value2 = "Another value" }))
    {
      logger.LogInformation("A Microsoft log");
    }
    
    Log.CloseAndFlush();
  }
}
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