<!-- enable asp.net core layout renderers --> <extensions> <addassembly="NLog.Web.AspNetCore"/> </extensions>
<!-- the targets to write to --> <targets> <!-- write logs to file --> <targetxsi:type="File"name="allfile"fileName="c:\temp\nlog-all-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
<!-- another file log, only own logs. Uses some ASP.NET core renderers --> <targetxsi:type="File"name="ownFile-web"fileName="c:\temp\nlog-own-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" /> </targets>
<!-- rules to map from logger name to target --> <rules> <!--All logs, including from Microsoft--> <loggername="*"minlevel="Trace"writeTo="allfile" />
<!--Skip non-critical Microsoft logs and so log only own logs--> <loggername="Microsoft.*"maxlevel="Info"final="true" /><!-- BlackHole without writeTo --> <loggername="*"minlevel="Trace"writeTo="ownFile-web" /> </rules> </nlog>
2020-12-10 14:35:02.5675 Info Message Template Auto Format enabled 2020-12-10 14:35:02.5858 Info Loading assembly: NLog.Web.AspNetCore 2020-12-10 14:35:02.6625 Info Adding target FileTarget(Name=allfile) 2020-12-10 14:35:02.6625 Info Adding target FileTarget(Name=ownFile-web) 2020-12-10 14:35:02.7270 Info Validating config: TargetNames=allfile, ownFile-web, ConfigItems=45, FilePath=C:\Users\SENB_014\source\repos\NlogExercise\NlogExercise\bin\Debug\netcoreapp3.1\nlog.config
nlog-all-2020-12-10.log
1 2 3 4 5 6 7 8 9 10
2020-12-10 14:35:02.7922||DEBUG|NlogExercise.Program|init main 2020-12-10 14:35:04.5343||INFO|Microsoft.Hosting.Lifetime|Now listening on: https://localhost:5001 2020-12-10 14:35:04.5463||INFO|Microsoft.Hosting.Lifetime|Now listening on: http://localhost:5000 2020-12-10 14:35:04.5463||INFO|Microsoft.Hosting.Lifetime|Application started. Press Ctrl+C to shut down. 2020-12-10 14:35:04.5463||INFO|Microsoft.Hosting.Lifetime|Hosting environment: Development 2020-12-10 14:35:04.5463||INFO|Microsoft.Hosting.Lifetime|Content root path: C:\Users\SENB_014\source\repos\NlogExercise\NlogExercise 2020-12-10 14:35:05.7936||INFO|NlogExercise.Controllers.WeatherForecastController|--Information-- 2020-12-10 14:35:05.7936||WARN|NlogExercise.Controllers.WeatherForecastController|Warning 2020-12-10 14:35:05.7936||ERROR|NlogExercise.Controllers.WeatherForecastController|--Error-- 2020-12-10 14:35:05.7936||FATAL|NlogExercise.Controllers.WeatherForecastController|--Critical--
nlog-own-2020-12-10.log
1 2 3 4 5
2020-12-10 14:35:02.7922||DEBUG|NlogExercise.Program|init main |url: |action: 2020-12-10 14:35:05.7936||INFO|NlogExercise.Controllers.WeatherForecastController|--Information-- |url: https://localhost/weatherforecast|action: Get 2020-12-10 14:35:05.7936||WARN|NlogExercise.Controllers.WeatherForecastController|Warning |url: https://localhost/weatherforecast|action: Get 2020-12-10 14:35:05.7936||ERROR|NlogExercise.Controllers.WeatherForecastController|--Error-- |url: https://localhost/weatherforecast|action: Get 2020-12-10 14:35:05.7936||FATAL|NlogExercise.Controllers.WeatherForecastController|--Critical-- |url: https://localhost/weatherforecast|action: Get