|
| 1 | +<?xml version="1.0" encoding="utf-8" ?> |
| 2 | + |
| 3 | +<!-- |
| 4 | +Copyright 2022 MONAI Consortium |
| 5 | +
|
| 6 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +you may not use this file except in compliance with the License. |
| 8 | +You may obtain a copy of the License at |
| 9 | +
|
| 10 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | +Unless required by applicable law or agreed to in writing, software |
| 13 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +See the License for the specific language governing permissions and |
| 16 | +limitations under the License. |
| 17 | +--> |
| 18 | + |
| 19 | +<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" |
| 20 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 21 | + autoReload="true" |
| 22 | + internalLogLevel="Debug" |
| 23 | + internalLogFile="${basedir}/logs/internal-nlog.txt"> |
| 24 | + |
| 25 | + <extensions> |
| 26 | + <add assembly="NLog.Web.AspNetCore"/> |
| 27 | + <add assembly="NLog.Extensions.Logging"/> |
| 28 | + </extensions> |
| 29 | + |
| 30 | + <variable name="logDir" value="${basedir}/logs/" /> |
| 31 | + |
| 32 | + <time type="AccurateUTC" /> |
| 33 | + |
| 34 | + <targets async="true"> |
| 35 | + <!-- File Target for all log messages with basic details --> |
| 36 | + <target xsi:type="File" name="allfile" fileName="${logDir}/MIG-${shortdate}.log" > |
| 37 | + <layout xsi:type="JsonLayout" includeEventProperties="true" includeScopeProperties="true"> |
| 38 | + <attribute name="timestamp" layout="${date:format=o}" /> |
| 39 | + <attribute name="level" layout="${level:upperCase=true}"/> |
| 40 | + <attribute name="logger" layout="${logger}" /> |
| 41 | + <attribute name="message" layout="${message:raw=true}" /> |
| 42 | + <attribute name="properties" layout="${message:raw=true}" /> |
| 43 | + </layout> |
| 44 | + </target> |
| 45 | + |
| 46 | + |
| 47 | + <!--Console Target for hosting lifetime messages to improve Docker / Visual Studio startup detection --> |
| 48 | + <target xsi:type="ColoredConsole" name="lifetimeConsole" layout="${longdate}|${event-properties:item=EventId:whenEmpty=0}|${uppercase:${level}}|${logger}|${scopenested}|${message} ${exception:format=tostring}" /> |
| 49 | + |
| 50 | + <target name="logstash" xsi:type="Network" address="${environment:LOGSTASH_URL}" newLine="true"> |
| 51 | + <layout xsi:type="JsonLayout" IncludeEventProperties="true" IncludeScopeProperties="true"> |
| 52 | + <attribute name="Tag" layout="${environment:ENVIRONMENT_NAME}" /> |
| 53 | + <attribute name="ServiceName" layout="${servicename}" /> |
| 54 | + <attribute name="ServiceVersion" layout="${serviceversion}" /> |
| 55 | + <attribute name="MachineName" layout="${machinename}" /> |
| 56 | + <attribute name="CorrelationId" layout="${mdlc:item=correlationId}"/> |
| 57 | + <attribute name="LoggerName" layout="${logger}"/> |
| 58 | + <attribute name="Level" layout="${level:upperCase=true}"/> |
| 59 | + <attribute name="Message" layout="${message}"/> |
| 60 | + <attribute name="Exception" layout="${onexception:${literal:text=|}"/> |
| 61 | + <attribute name="Exception2" layout="${exception:format=tostring}"/> |
| 62 | + </layout> |
| 63 | + </target> |
| 64 | + |
| 65 | + </targets> |
| 66 | + |
| 67 | + <!-- rules to map from logger name to target --> |
| 68 | + <rules> |
| 69 | + <!--All logs, including from Microsoft--> |
| 70 | + <logger name="*" minlevel="Trace" writeTo="allfile" /> |
| 71 | + |
| 72 | + <!--Output hosting lifetime messages to console target for faster startup detection --> |
| 73 | + <logger name="Microsoft.EntityFrameworkCore" minlevel="Warn" writeTo="lifetimeConsole" final="false" /> |
| 74 | + <logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole" final="false" /> |
| 75 | + <logger name="Monai.*" minlevel="Debug" writeTo="lifetimeConsole" final="false" /> |
| 76 | + |
| 77 | + <!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) --> |
| 78 | + <logger name="Microsoft.*" maxlevel="Info" final="true" /> |
| 79 | + <logger name="System.Net.Http.*" maxlevel="Info" final="true" /> |
| 80 | + |
| 81 | + <logger name="*" minlevel="Trace" writeTo="logstash" > |
| 82 | + <filters FilterDefaultAction="Log"> |
| 83 | + <when condition="length('${environment:LOGSTASH_URL}') < 10" action="Ignore" /> |
| 84 | + </filters> |
| 85 | + </logger> |
| 86 | + |
| 87 | + </rules> |
| 88 | +</nlog> |
0 commit comments