Skip to content

Instantly share code, notes, and snippets.

@sametoz
Last active May 3, 2020 08:09
Show Gist options
  • Save sametoz/a769b740eaa44b5a36305aeb09c30966 to your computer and use it in GitHub Desktop.
Save sametoz/a769b740eaa44b5a36305aeb09c30966 to your computer and use it in GitHub Desktop.
Serilog'un birinci seviyesini ifade eder.
public static void Main(string[] args)
{
var appSettings = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
var sinkOpts = new SinkOptions { TableName = "_Log", AutoCreateSqlTable = true, BatchPostingLimit = 10 };
Log.Logger = new LoggerConfiguration()
.WriteTo.MSSqlServer(
connectionString: appSettings.GetConnectionString("DB"),
sinkOptions: sinkOpts,
restrictedToMinimumLevel: LogEventLevel.Error
).CreateLogger();
try
{
Log.Information("Uygulama başlatılıyor...");
//Serilog kendisiyle alakalı bir problemle karşılaşırsa debug çıktısına yazdırır.
Serilog.Debugging.SelfLog.Enable(msg =>
{
Debug.Print(msg);
});
CreateWebHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Uygulama başlatılırken bir hata meydana geldi!");
}
finally
{
Log.CloseAndFlush();
}
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseSerilog(); //<- son olarak, Serilog'u EF Core uygulamasına bağlayalım.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment