-
Notifications
You must be signed in to change notification settings - Fork 151
Json NLog Config
Rolf Kristensen edited this page May 17, 2019
·
34 revisions
Introduced with NLog.Extensions.Logging ver. 1.5.0
var config = new ConfigurationBuilder()
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
LogManager.Configuration = new NLogLoggingConfiguration(config.GetSection("NLog"));{
"Logging": {
"NLog": {
"IncludeScopes": true,
}
},
"NLog": {
"autoReload": true,
"throwConfigExceptions": true,
"internalLogLevel": "info",
"internalLogFile": "c:/temp/internal-nlog.txt",
"extensions": {
"NLog.Extensions.Logging": {
"assembly": "NLog.Extensions.Logging"
}
},
"variables": {
"var_logdir": "c:/temp"
},
"default-wrapper": {
"type": "AsyncWrapper",
"overflowAction": "Block"
},
"targets": {
"all-file": {
"type": "File",
"fileName": "${var_logdir}/nlog-all-${shortdate}.log",
"layout": "${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}"
},
"own-console": {
"type": "Console",
"layout": "${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|${callsite}"
},
},
"rules": [
{
"logger": "*",
"minLevel": "Trace",
"writeTo": "all-file"
},
{
"logger": "Microsoft.*",
"minLevel": "Info",
"final": true
},
{
"logger": "*",
"minLevel": "Trace",
"writeTo": "own-console"
}
]
}
}