当前位置: 首页>>代码示例>>C#>>正文


C# ILoggerFactory.AddSerilog方法代码示例

本文整理汇总了C#中ILoggerFactory.AddSerilog方法的典型用法代码示例。如果您正苦于以下问题:C# ILoggerFactory.AddSerilog方法的具体用法?C# ILoggerFactory.AddSerilog怎么用?C# ILoggerFactory.AddSerilog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILoggerFactory的用法示例。


在下文中一共展示了ILoggerFactory.AddSerilog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Configure

        public void Configure(IApplicationBuilder app,
        IHostingEnvironment env,
        ILoggerFactory loggerFactory)
        {
            Log.Logger =
              new LoggerConfiguration()
                .MinimumLevel.Error()
                .WriteTo.TextWriter(System.Console.Out)
                .WriteTo.RollingFile(@"C:\temp\TSWebLog-{Date}.txt")
                .CreateLogger();

            loggerFactory.AddSerilog();

            app.UseStaticFiles();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }
开发者ID:hoetz,项目名称:aspnetCoreTypescriptKOSample,代码行数:26,代码来源:Startup.cs

示例2: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Information()
            #if DNXCORE50
                            .WriteTo.TextWriter(Console.Out)
            #else
                            .WriteTo.Trace()
                .WriteTo.RollingFile("log-{Date}.txt")
            #endif
            .CreateLogger();

            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();
            loggerFactory.AddSerilog();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseErrorPage(ErrorPageOptions.ShowAll);
            }
            else
            {
                app.UseErrorHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:Flank2k2,项目名称:MVC6Experiment,代码行数:34,代码来源:Startup.cs

示例3: Startup

        public Startup(
            IHostingEnvironment hostingEnvironment,
            ILoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger<Startup>();

            var configuration = new Configuration();
            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();
            var loggingConfiguration = configuration.GetSubKey("Logging");

            var serilog = new LoggerConfiguration()
                .MinimumLevel.Verbose()
                .Enrich.WithMachineName()
                .Enrich.WithProcessId()
                .Enrich.WithThreadId();

            if (string.Equals(hostingEnvironment.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
            {
                serilog.WriteTo.ColoredConsole();
            }

            string elasticSearchConnectionString;
            if (loggingConfiguration.TryGet("ElasticSearch:Server", out elasticSearchConnectionString))
            {
                serilog.WriteTo.ElasticSearch(node: new Uri(elasticSearchConnectionString));
            }

            loggerFactory.AddSerilog(serilog);
        }
开发者ID:Tragetaschen,项目名称:Entropy,代码行数:30,代码来源:Startup.cs

示例4: Configure

		public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
		{
			loggerFactory
				.AddSerilog(GetConfiguredSerilogger())
				.AddConsole(Configuration.GetSection("Logging"));

			app.UseMvc();
		}
开发者ID:pardahlman,项目名称:RawRabbit,代码行数:8,代码来源:Startup.cs

示例5: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddSerilog();
            _log = loggerFactory.CreateLogger("slydr");

            app.UseIISPlatformHandler();

            app.UseMvc();
        }
开发者ID:eaardal,项目名称:slydr,代码行数:9,代码来源:Startup.cs

示例6: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseStatusCodePages(subApp =>
                {
                    subApp.Run(async context =>
                    {
                        context.Response.ContentType = "text/html";
                        await context.Response.WriteAsync($"Error @ {context.Response.StatusCode}");
                    });
                });
            }

            logFactory.AddConsole(LogLevel.Trace);
            logFactory.AddSerilog();

            var logger = logFactory.CreateLogger<Startup>();

            logger.LogTrace("Trace msg");
            logger.LogDebug("Debug msg");
            logger.LogInformation("Info msg");
            logger.LogWarning("Warn msg");
            logger.LogError("Error msg");
            logger.LogCritical("Critical msg");

            app.UseMiddleware<RequestIdMiddleware>();

            //app.Run(ctx =>
            //{
            //    //throw new Exception("some error");
            //    //ctx.Response.StatusCode = 500;
            //    return Task.FromResult(0);
            //});


            //app.UseIISPlatformHandler();
            //app.UseFileServer();
            var router = new RouteBuilder(app)
                .MapGet("", async ctx => await ctx.Response.WriteAsync("Hello from routing"))
                .MapGet("sub", async ctx => await ctx.Response.WriteAsync("Hello from sub"))
                .MapGet("item/{id:int}", ctx => ctx.Response.WriteAsync($"Item ID: {ctx.GetRouteValue("id")}"))
                ;
            
            app.UseRouter(router.Build());
            app.UseMvc();

       
            //app.UseRequestCulture();
            //app.Run(async ctx => await ctx.Response.WriteAsync($"Hello {CultureInfo.CurrentCulture.DisplayName}"));
            //app.Run(async ctx => await ctx.Response.WriteAsync($"{Configuration["greeting"]}"));
        }
开发者ID:eaardal,项目名称:aspnet5-workshop,代码行数:56,代码来源:Startup.cs

示例7: UseTelemetry

 /// <summary>
 /// Configures logging.
 /// </summary>
 public static void UseTelemetry(
     this IApplicationBuilder appBuilder,
     ILoggerFactory loggerFactory,
     IConfigurationRoot configurationRoot,
     Func<LogEvent, bool> includeLogEvent)
 {
     appBuilder.UseApplicationInsightsRequestTelemetry();
     loggerFactory.AddDebug();
     loggerFactory.AddSerilog(CreateLogger(configurationRoot, includeLogEvent));
 }
开发者ID:CSClassroom,项目名称:CSClassroom,代码行数:13,代码来源:ApplicationBuilderExtensions.cs

示例8: Startup

        public Startup(ILoggerFactory loggerFactory)
        {
            var serilogLogger = new LoggerConfiguration()
                .WriteTo
                .TextWriter(Console.Out)
                .MinimumLevel.Verbose()
                .CreateLogger();

            Log.Logger = serilogLogger;
            loggerFactory.MinimumLevel = LogLevel.Debug;
            loggerFactory.AddSerilog(serilogLogger);
        }
开发者ID:rainymaplesoft,项目名称:IdentityServer3.Samples,代码行数:12,代码来源:Startup.cs

示例9: Startup

        public Startup(ILoggerFactory loggerFactory)
        {
            var serilogLogger = new LoggerConfiguration()
                .WriteTo
                .TextWriter(Console.Out)
#if DNX451
                .WriteTo.Elasticsearch()
#endif
                .MinimumLevel.Verbose()
                .CreateLogger();

            loggerFactory.MinimumLevel = LogLevel.Debug;
            loggerFactory.AddSerilog(serilogLogger);
        }
开发者ID:ehvattum,项目名称:aspnet-5-samples,代码行数:14,代码来源:Startup.cs

示例10: Configure

        // 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)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            loggerFactory.AddSerilog();

            app.UseMiddleware<RedirectWwwMiddleware>()
                .UseMiddleware<RedirectHttpMiddleware>()
                .UseStaticFiles()
                .UseMvc();

            if (env.IsDevelopment())
                app.UseDeveloperExceptionPage();
        }
开发者ID:yavtech,项目名称:ICanHasDotnetCore,代码行数:15,代码来源:Startup.cs

示例11: Startup

        public Startup(IApplicationEnvironment appEnv, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory)
        {
            var serilogLogger = new LoggerConfiguration()
                .WriteTo.ColoredConsole()
                .MinimumLevel.Verbose()
                .CreateLogger();

            Log.Logger = serilogLogger;
            loggerFactory.MinimumLevel = LogLevel.Debug;
            loggerFactory.AddSerilog(serilogLogger);

            _appEnv = appEnv;
            _hostingEnv = hostingEnv;
            _loggerFactory = loggerFactory;
        }
开发者ID:syoguran,项目名称:ModernShopping,代码行数:15,代码来源:Startup.cs

示例12: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddSerilog();

            app.Run(async context =>
            {
                var myClass = context.RequestServices.GetService<MyClass>();

                myClass.DoSomething(1);
                myClass.DoSomething(20);
                myClass.DoSomething(-20);

                await context.Response.WriteAsync("Hello World!");
            });
        }
开发者ID:jeffogata,项目名称:aspnet-logging-02-cli,代码行数:15,代码来源:Startup.cs

示例13: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ApplicationContextSeedData seedData)
        {
			loggerFactory.AddSerilog();
			loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug(LogLevel.Verbose);


            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");

                // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
                try
                {
                    using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
                        .CreateScope())
                    {
                        serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
                             .Database.Migrate();
                    }
                }
                catch { }
            }

            app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());

            app.UseStaticFiles();

            app.UseIdentity();

            // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

			await seedData.EnsureSeedData();
		}
开发者ID:ZacMarcus,项目名称:Sharelytics_RC1,代码行数:48,代码来源:Startup.cs

示例14: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
        {
            loggerfactory.AddSerilog(GetLoggerConfiguration());

            app.UseDatabaseErrorPage()
                .UseStaticFiles()
                .UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "default",
                        template: "{controller}/{action}/{id?}",
                        defaults: new { controller = "Home", action = "Index" });
                });

            // Populates the MusicStore sample data
            SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait();
        }
开发者ID:JensKlambauer,项目名称:MVC6_Testprojects,代码行数:17,代码来源:Startup.cs

示例15: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env)
        {
            loggerFactory.AddSerilog();
            loggerFactory.AddConsole((category, level) => category == typeof(Startup).FullName);
            var startupLogger = loggerFactory.CreateLogger<Startup>();

            app.UseIISPlatformHandler();

            startupLogger.LogInformation("Application startup complete!");
            startupLogger.LogCritical("This is a critical message");
            startupLogger.LogDebug("This is a Debug message");
            startupLogger.LogWarning("This is a warning message");
            startupLogger.LogError("This is an error message");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseStatusCodePages(subApp =>
                {
                    subApp.Run(async context =>
                    {
                        context.Response.ContentType = "text/html";
                        await context.Response.WriteAsync($"<strong> You got a {context.Response.StatusCode}<strong>");
                        await context.Response.WriteAsync(new string(' ', 512));  // Padding for IE
                    });
                });
                app.UseExceptionHandler(subApp =>
                {
                    subApp.Run(async context =>
                    {
                        context.Response.ContentType = "text/html";
                        await context.Response.WriteAsync("<strong> Oops! Something went wrong :( </strong>");
                        await context.Response.WriteAsync(new string(' ', 512));  // Padding for IE
                    });
                });
            }

            app.Run((context) =>
            {
                context.Response.StatusCode = 404;
                return Task.FromResult(0);
            });
        }
开发者ID:naeemsarfraz,项目名称:aspnet5-workshop,代码行数:47,代码来源:Startup.cs


注:本文中的ILoggerFactory.AddSerilog方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。