/// <inheritdoc/> public void Perform(LoggingSettings settings, IBootStageBuilder builder) { var entryAssembly = builder.GetAssociation(WellKnownAssociations.EntryAssembly) as Assembly; var environment = builder.GetAssociation(WellKnownAssociations.Environment) as Environment; _initialExecutionContext = ExecutionContextManager.SetInitialExecutionContext(); #pragma warning disable CA2000 var loggerFactory = settings.LoggerFactory ?? new LoggerFactory(); #pragma warning restore CA2000 _isProduction = environment == Environment.Production; var logAppender = settings.LogAppender; if (logAppender == null) { logAppender = (_isProduction && !settings.UseDefaultInAllEnvironments) ? new JsonLogAppender(GetCurrentLoggingContext) : new DefaultLogAppender(GetCurrentLoggingContext, loggerFactory) as ILogAppender; } var logAppenders = Dolittle.Logging.Bootstrap.Boot.Start(logAppender, entryAssembly); Dolittle.Logging.ILogger logger = settings.Logger ?? new Logger(logAppenders); logger.Information($"<********* BOOTSTAGE : Logging *********>"); builder.Associate(WellKnownAssociations.Logger, logger); _executionContextManager = new ExecutionContextManager(logger); builder.Bindings.Bind <Dolittle.Logging.ILogger>().To(logger); builder.Bindings.Bind <ILoggerFactory>().To(loggerFactory); builder.Bindings.Bind <IExecutionContextManager>().To(_executionContextManager); }
LoggingContext CreateLoggingContextFrom(ExecutionContext executionContext) => new LoggingContext { Application = executionContext.Application, BoundedContext = executionContext.BoundedContext, CorrelationId = executionContext.CorrelationId, Environment = executionContext.Environment, TenantId = executionContext.Tenant };
/// <summary> /// Convert from <see cref="Dolittle.Execution.ExecutionContext"/> to <see cref="ExecutionContext"/> /// </summary> /// <param name="executionContext"><see cref="Dolittle.Execution.ExecutionContext"/> to convert from</param> /// <returns>Converted <see cref="ExecutionContext"/></returns> public static ExecutionContext ToProtobuf(this Dolittle.Execution.ExecutionContext executionContext) { var protobuf = new ExecutionContext { Application = executionContext.Application.ToProtobuf(), BoundedContext = executionContext.BoundedContext.ToProtobuf(), Tenant = executionContext.Tenant.ToProtobuf(), CorrelationId = executionContext.CorrelationId.ToProtobuf(), Environment = executionContext.Environment.Value, Culture = executionContext.Culture?.Name ?? CultureInfo.InvariantCulture.Name }; executionContext.Claims.ToProtobuf().ForEach(protobuf.Claims.Add); return(protobuf); }