Integrate NLog for structured file-based logging by adding configuration to appsettings.json and initializing NLog in Program.cs. Wrap application startup in a try-catch block to log unhandled exceptions. No changes to core application logic.
59 lines
1.3 KiB
JSON
59 lines
1.3 KiB
JSON
{
|
|
"Logging": {
|
|
"LogLevel": {
|
|
"Default": "Information",
|
|
"Microsoft.AspNetCore": "Warning"
|
|
}
|
|
},
|
|
"AllowedHosts": "*",
|
|
"Kestrel": {
|
|
"EndpointDefaults": {
|
|
"Protocols": "Http1"
|
|
}
|
|
},
|
|
"EnableSwagger": true,
|
|
"NLog": {
|
|
"throwConfigExceptions": true,
|
|
"variables": {
|
|
"logDirectory": "E:\\LogFiles\\Digital Data\\FakeNTLMServer",
|
|
"logFileNamePrefix": "${shortdate}-FakeNTLMServer"
|
|
},
|
|
"targets": {
|
|
"infoLogs": {
|
|
"type": "File",
|
|
"fileName": "${logDirectory}\\${logFileNamePrefix}-Info.log",
|
|
"maxArchiveDays": 30
|
|
},
|
|
"errorLogs": {
|
|
"type": "File",
|
|
"fileName": "${logDirectory}\\${logFileNamePrefix}-Error.log",
|
|
"maxArchiveDays": 30
|
|
},
|
|
"criticalLogs": {
|
|
"type": "File",
|
|
"fileName": "${logDirectory}\\${logFileNamePrefix}-Critical.log",
|
|
"maxArchiveDays": 30
|
|
}
|
|
},
|
|
// Trace, Debug, Info, Warn, Error and *Fatal*
|
|
"rules": [
|
|
{
|
|
"logger": "*",
|
|
"minLevel": "Info",
|
|
"maxLevel": "Warn",
|
|
"writeTo": "infoLogs"
|
|
},
|
|
{
|
|
"logger": "*",
|
|
"level": "Error",
|
|
"writeTo": "errorLogs"
|
|
},
|
|
{
|
|
"logger": "*",
|
|
"level": "Fatal",
|
|
"writeTo": "criticalLogs"
|
|
}
|
|
]
|
|
}
|
|
}
|