Ejemplo n.º 1
0
        /// <summary> Configure the Mass Transit Service Bus to use Microsoft.Extensions.Logging. </summary>
        /// <param name="configurator">The configurator to act on. </param>
        /// <param name="loggerFactory">The ILoggerFactory. If none supplied, will be created.</param>
        public static ILoggerFactory UseExtensionsLogging(this IBusFactoryConfigurator configurator, ILoggerFactory loggerFactory)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            return(ExtensionsLogger.Use(loggerFactory));
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            ExtensionsLogger.Use(loggerFactory);

            app.UseMvc();

            Services = app.ApplicationServices;

            // start micro services
            applicationLifetime.ApplicationStarted.Register(OnStart);
            applicationLifetime.ApplicationStopping.Register(OnStopping);
            applicationLifetime.ApplicationStopped.Register(OnStopped);
        }
Ejemplo n.º 3
0
        static async Task Main(string[] args)
        {
            Configure(args);
            var svcProvider = ServiceProvider();
            var busControl  = svcProvider.GetRequiredService <IBusControl>();

            if (Logger.Current.GetType() == typeof(TraceLogger))
            {
                ExtensionsLogger.Use(svcProvider.GetRequiredService <ILoggerFactory>());
            }
            var logger = svcProvider
                         .GetRequiredService <ILoggerFactory>()
                         .CreateLogger <Program>();
            await busControl.StartAsync().ConfigureAwait(false);

            Console.WriteLine("Enter message (or ctrl+c to exit)");
            try
            {
                while (true) // hackish
                {
                    Console.Write("> ");
                    var value = Console.ReadLine();
                    if (!string.IsNullOrEmpty(value))
                    {
                        await busControl.Publish(ValueEnteredFactory.Create(value))
                        .ConfigureAwait(false);

                        Console.WriteLine($"published {value}");
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "'while' exception");
            }
            finally
            {
                busControl.Stop();
            }
        }