Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            SmartPropertiesLayoutRenderer.Register();

            // Add framework services.
            services
            .AddMvc()
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.Converters.Add(new JsonStringConverter());
            });

            services.Configure <RazorViewEngineOptions>(options =>
            {
                options.ViewLocationExpanders.Add(new RelativeViewLocationExpander("src"));
            });

            services.AddSingleton(_hostingEnvironment.ContentRootFileProvider);

            //services.AddApiVersioning(setupAction =>
            //{
            //    setupAction.ApiVersionReader = new HeaderApiVersionReader(HeaderFieldName.ApiVersion);
            //});;

            services.AddSingleton <IConfiguration>(_configuration);
            services.AddSingleton <ILoggerFactory>(
                new LoggerFactory()
                .UseSemanticExtensions(_hostingEnvironment.EnvironmentName, "Reusable.Apps.Server")
                .AddObserver <NLogRx>()
                );

            //services.AddScoped(serviceProvider => new ClientInfo(HeaderPrefix, serviceProvider.GetService<IMultipartName>()));
        }
Beispiel #2
0
        public static void ConsoleColorizer()
        {
            SmartPropertiesLayoutRenderer.Register();

            var loggerFactory = new LoggerFactory
            {
                Observers =
                {
                    new ColoredConsoleRx(),
                },
                Configuration = new LoggerFactoryConfiguration
                {
                    Attachments = new HashSet <ILogAttachment>
                    {
                        new Timestamp <DateTimeUtc>(),
                    }
                }
            };

            var consoleLogger = loggerFactory.CreateLogger("ConsoleTemplateTest");

            consoleLogger.WriteLine(m => m
                                    .text(">")
                                    .span(s => s.text("foo").color(ConsoleColor.Red))
                                    .text(" bar ")
                                    .span(s => s
                                          .text("foo ")
                                          .span(ss => ss.text("bar").backgroundColor(ConsoleColor.Gray))
                                          .text(" baz")
                                          .backgroundColor(ConsoleColor.DarkYellow)
                                          )
                                    );
        }
Beispiel #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            SmartPropertiesLayoutRenderer.Register();


            services.AddSingleton <ILoggerFactory>
            (
                new LoggerFactory()
                .AttachObject("Environment", HostingEnvironment.EnvironmentName)
                .AttachObject("Product", "Mailr")
                .AttachScope()
                .AttachSnapshot()
                .Attach <Timestamp <DateTimeUtc> >()
                .AttachElapsedMilliseconds()
                .AddObserver <NLogRx>()
            );

            services
            .AddMvc()
            .AddExtensions();

            services.AddScoped <ICssProvider, CssProvider>();
            services.Configure <RazorViewEngineOptions>(options =>
            {
                const string prefix = "src";

                options
                .ViewLocationExpanders
                .Add(new RelativeViewLocationExpander(prefix));
            });

            var emailClient = Configuration["emailClient"];

            switch (emailClient)
            {
            case nameof(SmtpClient):
                services.AddSingleton <IEmailClient, SmtpClient>();
                break;

            case nameof(OutlookClient):
                services.AddSingleton <IEmailClient, OutlookClient>();
                break;

            default:
                throw new ArgumentOutOfRangeException($"Invalid EmailClient: {emailClient}. Expected {nameof(SmtpClient)} or {nameof(OutlookClient)}.");
            }

            services.AddSingleton <IHostedService, WorkItemQueueService>();
            services.AddSingleton <IWorkItemQueue, WorkItemQueue>();

            services.AddScoped <ValidateModel>();
        }
Beispiel #4
0
        public static void SemanticExtensions()
        {
            SmartPropertiesLayoutRenderer.Register();

            var fileProvider = new RelativeFileProvider(new PhysicalFileProvider(), typeof(Demo).Assembly.Location);

            var loggerFactory =
                new LoggerFactory()
                .UseSemanticExtensions("development", "Reusable.Apps.Console")
                .AddObserver <NLogRx>();
            //.UseConfiguration(LoggerFactoryConfiguration.Load(fileProvider.GetFileInfo(@"cfg\omnilog.json").CreateReadStream()));

            var logger = loggerFactory.CreateLogger("Demo");

            logger.Log(Abstraction.Layer.Infrastructure().Routine("SemLogTest").Running());

            // Opening outer-transaction.
            using (logger.BeginScope().WithCorrelationId().WithCorrelationContext(new { Name = "OuterScope", CustomerId = 123 }).AttachElapsed())
            {
                // Logging some single business variable and a message.
                logger.Log(Abstraction.Layer.Business().Variable(new { foo = "bar" }), log => log.Message("Hallo variable!"));

                // Opening innter-transaction.
                using (logger.BeginScope().WithCorrelationId().WithCorrelationContext(new { Name = "InnerScope", ItemId = 456 }).AttachElapsed())
                {
                    // Logging an entire object in a single line.
                    var customer = new { FirstName = "John", LastName = "Doe" };
                    logger.Log(Abstraction.Layer.Business().Variable(new { customer }));

                    // Logging multiple variables in a single line.
                    var baz = 123;
                    var qux = "quux";

                    logger.Log(Abstraction.Layer.Infrastructure().Composite(new { multiple = new { baz, qux } }));

                    // Logging action results.
                    logger.Log(Abstraction.Layer.Infrastructure().Routine("DoSomething").Running());
                    logger.Log(Abstraction.Layer.Infrastructure().Routine("DoSomething").Canceled(), "No connection.");
                    logger.Log(Abstraction.Layer.Infrastructure().Routine("DoSomething").Faulted(), new DivideByZeroException("Cannot divide."));
                }
            }
        }
Beispiel #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            SmartPropertiesLayoutRenderer.Register();

            // Add framework services.
            services
            .AddMvc()
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.Converters.Add(new JsonStringConverter());
            });

            services.Configure <RazorViewEngineOptions>(options =>
            {
                options.ViewLocationExpanders.Add(new RelativeViewLocationExpander("src"));
            });

            services.AddSingleton(_hostingEnvironment.ContentRootFileProvider);

            //services.AddApiVersioning(setupAction =>
            //{
            //    setupAction.ApiVersionReader = new HeaderApiVersionReader(HeaderFieldName.ApiVersion);
            //});;

            services.AddSingleton <IConfiguration>(_configuration);
            services.AddSingleton <ILoggerFactory>(
                new LoggerFactory()
                .AttachObject("Environment", _hostingEnvironment.EnvironmentName)
                .AttachObject("Product", "Reusable.Apps.Server")
                .AttachScope()
                .AttachSnapshot()
                .Attach <Timestamp <DateTimeUtc> >()
                //.AttachElapsedMilliseconds()
                .AddObserver <NLogRx>()
                );

            services.AddSingleton(typeof(ILogger <>), typeof(Logger <>));

            //services.AddScoped(serviceProvider => new ClientInfo(HeaderPrefix, serviceProvider.GetService<IMultipartName>()));
        }
Beispiel #6
0
        public static void SemanticExtensions()
        {
            SmartPropertiesLayoutRenderer.Register();

            //var fileProvider = new RelativeResourceProvider(new PhysicalFileProvider(), typeof(Demo).Assembly.Location);

            var loggerFactory =
                new LoggerFactory()
                .AttachObject("Environment", "Demo")
                .AttachObject("Product", "Reusable.Apps.Console")
                .AttachScope()
                .AttachSnapshot(SimpleJsonConverter <Person> .Create(x => new { x.FirstName, x.LastName }))
                .Attach <Timestamp <DateTimeUtc> >()
                .AttachElapsedMilliseconds()
                .AddObserver <NLogRx>();
            // UseConverter<Something>(x => x.ToString());
            //.UseConfiguration(LoggerFactoryConfiguration.Load(fileProvider.GetFileInfo(@"cfg\omnilog.json").CreateReadStream()));

            var logger = loggerFactory.CreateLogger("Demo");

            logger.Log(Abstraction.Layer.Infrastructure().Routine("SemLogTest").Running());
            logger.Log(Abstraction.Layer.Infrastructure().Meta(new { Null = (string)null }));


            // Opening outer-transaction.
            using (logger.BeginScope().WithCorrelationHandle("Blub").WithRoutine("MyRoutine").WithCorrelationContext(new { Name = "OuterScope", CustomerId = 123 }).AttachElapsed())
            {
                // Logging some single business variable and a message.
                logger.Log(Abstraction.Layer.Business().Variable(new { foo = "bar" }), log => log.Message("Hallo variable!"));
                logger.Log(Abstraction.Layer.Database().Counter(new { RowCount = 7 }));
                logger.Log(Abstraction.Layer.Database().Decision("blub").Because("bluby"));

                // Opening inner-transaction.
                using (logger.BeginScope().WithCorrelationContext(new { Name = "InnerScope", ItemId = 456 }).AttachElapsed())
                {
                    logger.Log(Abstraction.Layer.Infrastructure().RoutineFromScope().Running());

                    var correlationIds = logger.Scopes().CorrelationIds <string>().ToList();

                    // Logging an entire object in a single line.
                    //var customer = new { FirstName = "John", LastName = "Doe" };
                    var customer = new Person
                    {
                        FirstName       = "John",
                        LastName        = null,
                        Age             = 123.456,
                        DBNullTest      = DBNull.Value,
                        GraduationYears = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 },
                        Nicknames       = { "Johny", "Doe" }
                    };
                    logger.Log(Abstraction.Layer.Business().Variable(new { customer }));

                    // Logging multiple variables in a single line.
                    var baz = 123;
                    var qux = "quux";

                    logger.Log(Abstraction.Layer.Infrastructure().Composite(new { multiple = new { baz, qux } }));

                    // Logging action results.
                    logger.Log(Abstraction.Layer.Infrastructure().Routine("DoSomething").Running());
                    logger.Log(Abstraction.Layer.Infrastructure().Routine("DoSomething").Canceled().Because("No connection."));
                    logger.Log(Abstraction.Layer.Infrastructure().Routine("DoSomething").Faulted(), new DivideByZeroException("Cannot divide."));
                    logger.Log(Abstraction.Layer.Service().Decision("Don't do this.").Because("Disabled."));
                }
            }
        }