/// <summary> /// Registers the specified context. /// </summary> /// <param name="context">The context.</param> public void Register([NotNull] IHostingConventionContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (_options.UseDefaults) { context.Builder.ConfigureMetricsWithDefaults((ctx, builder) => { new MetricsBuilder(_scanner, context.Get <IAssemblyProvider>(), context.Get <IAssemblyCandidateFinder>(), builder, ctx.HostingEnvironment, ctx.Configuration, _diagnosticSource, context.Properties).Build(); }); } else { context.Builder.ConfigureMetrics((ctx, builder) => { new MetricsBuilder(_scanner, context.Get <IAssemblyProvider>(), context.Get <IAssemblyCandidateFinder>(), builder, ctx.HostingEnvironment, ctx.Configuration, _diagnosticSource, context.Properties).Build(); }); } context.Builder.ConfigureServices((_, services) => services.AddAppMetricsHealthPublishing()); }
/// <inheritdoc /> public void Register([NotNull] IHostingConventionContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } context.Scanner.ExceptConvention(typeof(SerilogExtensionsConvention)); context.Builder.ConfigureServices((context, services) => { foreach (var item in services .Where(x => x.ImplementationType?.FullName.StartsWith("Microsoft.Extensions.Logging") == true) .ToArray() ) { services.Remove(item); } }); context.Builder.UseSerilog( (ctx, loggerConfiguration) => { new SerilogBuilder( _scanner, context.AssemblyProvider, context.AssemblyCandidateFinder, new RocketEnvironment(ctx.HostingEnvironment), ctx.Configuration, loggerConfiguration, _diagnosticSource, context.Properties ).Configure(); }, _options.PreserveStaticLogger, _options.WriteToProviders ); }