本文整理汇总了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" });
});
}
示例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?}");
});
}
示例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);
}
示例4: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory
.AddSerilog(GetConfiguredSerilogger())
.AddConsole(Configuration.GetSection("Logging"));
app.UseMvc();
}
示例5: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddSerilog();
_log = loggerFactory.CreateLogger("slydr");
app.UseIISPlatformHandler();
app.UseMvc();
}
示例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"]}"));
}
示例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));
}
示例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);
}
示例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);
}
示例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();
}
示例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;
}
示例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!");
});
}
示例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();
}
示例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();
}
示例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);
});
}