Last active
May 3, 2020 08:09
-
-
Save sametoz/a769b740eaa44b5a36305aeb09c30966 to your computer and use it in GitHub Desktop.
Serilog'un birinci seviyesini ifade eder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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