Как этого добиться?
Вот мои файлы:
Код: Выделить всё
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Splunk" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
//"Enrich": [ "FromLogContext" ], // "WithMachineName", "WithProcessId", "WithThreadId" ],
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "c:\\home\\LogFiles\\APP NM\\App-.log", //"Logs/applog-.txt",
"rollingInterval": "Day",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} {CorrelationId} [{Level:u3}] {Username} {Message}{NewLine:1}{Exception:1}"
// "${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}"
}
},
{
"Name": "File",
"Args": {
"path": "c:\\home\\LogFiles\\APP NM\\App-.json",
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"
}
},
{
"Name": "EventCollector",
"Args": {
"splunkHost": "https:HOST.COM:8088",
"eventCollectorToken": tokenValue,
"uriPath": urlPath,
"index": index,
"source": "APP NM"
//"sourceType": "_json",
//"restrictedToMinimumLevel": "Information",
//"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"
}
}
],
"Properties": {
"ApplicationName": "GapsWeb"
}
},
Код: Выделить всё
// Configure Serilog from
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.CreateLogger();
try
{
builder.Host.UseSerilog();
// Add services to the container.
builder.Services.AddControllersWithViews().AddJsonOptions(options =>
// ......
app.UseStaticFiles();
app.UseSerilogRequestLogging();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Application start-up failed");
}
finally
{
Log.CloseAndFlush();
}
Код: Выделить всё
{"time":"1756160042.162","event":{"Level":"Information","MessageTemplate":"HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000} ms","RenderedMessage":"HTTP \"GET\" \"/\" responded 401 in 2.5741 ms", ........ ~ 40+ lines
Подробнее здесь: https://stackoverflow.com/questions/797 ... ges-in-one