示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Use FromLoggingProxy to enrich the serilog output with diagnostic, tracking, error and performance logging.
            ILogger serilog = new LoggerConfiguration()
                              .Enrich.FromLogProxy()
                              .Destructure.ByIgnoringProperties <ResponseDto>(x => x.Password)
                              .WriteTo.Seq("http://localhost:5341")
                              .CreateLogger();

            Log.Logger = serilog;

            services.ActivateLogTypes(LogTypes.All);

            services.AddSingleton(serilog);
            services.TryAddSingletonWithLogProxy <IValueAccess, ValueAccess>();

            services.AddRouting(options => options.LowercaseUrls = true);

            services.AddMvc();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "My API", Version = "v1"
                });
            });


            services.AddControllers();
        }
示例#2
0
        //public void ConfigureServices(IServiceCollection services)
        //{

        //}

        public static void ConfigureServicesWithLogSink(
            IServiceCollection services,
            TextWriter textWriter,
            string outputTemplate)
        {
            ILogger serilog = new LoggerConfiguration()
                              .Enrich.FromLogProxy()
                              .Destructure.ByIgnoringProperties <ResponseDto>(x => x.Password)
                              .WriteTo.Seq("http://localhost:5341")
                              .WriteTo.TextWriter(textWriter, outputTemplate: outputTemplate)
                              .CreateLogger();

            Log.Logger = serilog;

            services.ActivateLogTypes(LogTypes.All);

            services.AddSingleton(serilog);
            services.TryAddSingletonWithLogProxy <IValueAccess, ValueAccess>();

            services.AddRouting(options => options.LowercaseUrls = true);

            services.AddMvc();

            services.AddControllers();
        }