Difference between revisions of "Common Logging"
From Hiasobi - FHIR
Brett Esler (Talk | contribs) |
Brett Esler (Talk | contribs) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
* External adapters e.g. NLog - Common.Logging.NLog20.dll | * External adapters e.g. NLog - Common.Logging.NLog20.dll | ||
* Configuration: <app>.exe.config - configure logging | * Configuration: <app>.exe.config - configure logging | ||
− | * | + | * Default is no logging (null logger) |
− | + | ||
== NLog Configuration == | == NLog Configuration == | ||
Line 12: | Line 11: | ||
* NLog.dll - NLog2 core library | * NLog.dll - NLog2 core library | ||
* NLog.config - external configuration file for NLog; (may be done in-line in the <app>.exe.config) | * NLog.config - external configuration file for NLog; (may be done in-line in the <app>.exe.config) | ||
− | * <app>.exe.config | + | * <app>.exe.config - inject dependency and reference NLog.cofig external file |
+ | |||
+ | <code> | ||
+ | <?xml version="1.0" encoding="utf-8" ?> | ||
+ | <configuration> | ||
+ | <configSections> | ||
+ | <sectionGroup name="common"> | ||
+ | <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> | ||
+ | </sectionGroup> | ||
+ | </configSections> | ||
+ | <common> | ||
+ | <logging> | ||
+ | <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20"> | ||
+ | <arg key="configType" value="FILE" /> | ||
+ | <arg key="configFile" value="NLog.config" /> | ||
+ | </factoryAdapter> | ||
+ | </logging> | ||
+ | </common> | ||
+ | </configuration> | ||
+ | </code> | ||
+ | |||
+ | == NLog Typical Configuration == | ||
+ | The typical logging location for Hiasobi. 7 day rolling log in the %AppData%\<adapter name>\logs folder. | ||
+ | |||
+ | * Current log: log.today.txt | ||
+ | * Past logs: log.<n>.txt | ||
+ | * e.g. log.0.txt, log.1.txt, ..., log.6.txt - most recent to oldest logs | ||
+ | |||
+ | |||
<code> | <code> | ||
− | <?xml version="1.0" encoding="utf-8" ?> | + | <?xml version="1.0" encoding="utf-8" ?> |
− | < | + | <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" |
− | < | + | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
− | + | <targets> | |
− | + | <target xsi:type="File" | |
− | + | name="userlog" layout="${longdate} ${logger} ${message} ${exception:Message,StackTrace}" | |
− | + | fileName="${specialfolder:ApplicationData}/<adapter name>/logs/log.today.txt" | |
− | + | archiveFileName="${specialfolder:ApplicationData}/TelstraRunner/logs/log.{#}.txt" | |
− | + | archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="7" concurrentWrites="true" /> | |
− | + | <target xsi:type="Console" name="console" /> | |
− | + | </targets> | |
− | + | <rules> | |
− | + | <logger name="*" minlevel="Trace" writeTo="userlog" /> | |
− | </ | + | </rules> |
− | </ | + | </nlog> |
− | </ | + | |
</code> | </code> |
Latest revision as of 11:27, 29 July 2016
Common Logging
Supported as follows:
- Common.Logging.dll (v2.1.1.0) built in
- External adapters e.g. NLog - Common.Logging.NLog20.dll
- Configuration: <app>.exe.config - configure logging
- Default is no logging (null logger)
NLog Configuration
Require libraries and configuration
- Common.Logging.NLog20.dll - NLog2 common logging adapter
- NLog.dll - NLog2 core library
- NLog.config - external configuration file for NLog; (may be done in-line in the <app>.exe.config)
- <app>.exe.config - inject dependency and reference NLog.cofig external file
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <sectionGroup name="common"> <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> </sectionGroup> </configSections> <common> <logging> <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20"> <arg key="configType" value="FILE" /> <arg key="configFile" value="NLog.config" /> </factoryAdapter> </logging> </common> </configuration>
NLog Typical Configuration
The typical logging location for Hiasobi. 7 day rolling log in the %AppData%\<adapter name>\logs folder.
- Current log: log.today.txt
- Past logs: log.<n>.txt
- e.g. log.0.txt, log.1.txt, ..., log.6.txt - most recent to oldest logs
<?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <targets> <target xsi:type="File" name="userlog" layout="${longdate} ${logger} ${message} ${exception:Message,StackTrace}" fileName="${specialfolder:ApplicationData}/<adapter name>/logs/log.today.txt" archiveFileName="${specialfolder:ApplicationData}/TelstraRunner/logs/log.{#}.txt" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="7" concurrentWrites="true" /> <target xsi:type="Console" name="console" /> </targets> <rules> <logger name="*" minlevel="Trace" writeTo="userlog" /> </rules> </nlog>