"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Elasticsearch" ],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "Elasticsearch",
"Args": {
"nodeUris": "http://localhost:9200",
"indexFormat": "logs-{0:yyyy.MM.dd}",
"autoRegisterTemplate": true,
"bufferBaseFilename": "serilog-buffer",
"bufferFileSizeLimitBytes": 10240,
"bufferLogShippingInterval": "00:00:10"
}
}
]
}
public static int Main(string[] args)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
try
{
Log.Information("Starting up");
CreateWebHostBuilder(args).Build().Run();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Application start-up failed");
return 1;
}
finally
{
Log.CloseAndFlush();
}
}
This code reads the configuration from the appsettings.json file and sets up the logger with the specified sinks. 7. Run your application and check the Elasticsearch instance for the logs.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-22 22:19:48 +0000
Seen: 14 times
Last updated: May 22 '23
How can one ensure that sub-classes have uniform method parameters in TypeScript?
How can the calculation of matrix determinant be performed using CUDA?
How can code repetition be prevented when using (box)plot functions?
When I attempt to generate a database, why does the azure-cosmos-emulator become unresponsive?
What steps can I take to prevent my webpage from slowing down when all parts of a div are displayed?