COMMON.LOGGING
Larry Nung
AGENDA
Introduction
Getting started
Reference
Q & A
2
INTRODUCTION
3
INTRODUCTION
 Provides a simple logging abstraction to switch
between different logging implementations.
 Support
 Log4net
 Nlog
 Microsoft Enterprise Library logging
 Microsoft Application Insights
 Microsoft Event Tracing for Windows
 Serilog
4
GETTING STARTED
5
GETTING STARTED
Install
Common.Logging
and adapter
pckage via NuGet
Register and
configure
Common.Logging
Configure adapter
log
Write log with
Common.Logging
6
INSTALL COMMON.LOGGING AND ADAPTER
PCKAGE VIA NUGET
7
INSTALL COMMON.LOGGING AND ADAPTER
PCKAGE VIA NUGET
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Common.Logging" version="3.3.1"
targetFramework="net45" />
<package id="Common.Logging.Core"
version="3.3.1" targetFramework="net45" />
<package id="Common.Logging.Log4Net1215"
version="3.3.1" targetFramework="net45" />
<package id="log4net" version="2.0.5"
targetFramework="net45" />
</packages> 8
REGISTER AND CONFIGURE
COMMON.LOGGING
<?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.Log4Net.Log4NetLoggerFactoryAdapter,
Common.Logging.Log4net1215">
<!--<arg key="configType" value="INLINE" />-->
<!--<arg key="configType" value="FILE" />-->
<arg key="configType" value="FILE-WATCH" />
<arg key="configFile" value="~/log4net.config" />
</factoryAdapter>
</logging>
</common>
</configuration>
9
CONFIGURE ADAPTER LOG
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="FullAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="LogFull.log" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value="yyyyMMdd" />
<maximumFileSize value="10MB" />
<maxSizeRollBackups value="-1" />
<CountDirection value="1" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern
value="%date&#x9;[%thread]&#x9;%level&#x9;%logger&#x9;%identity&#x9;-
%message%newline" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="FullAppender" />
</root>
</log4net>
10
WRITE LOG WITH COMMON.LOGGING
using Common.Logging;
...
var logger = LogManager.GetLogger<Program>();
logger.Info("Hello World!");
...
11
REFERENCE
12
REFERENCE
 Common Infrastructure Libraries for .NET
 http://netcommon.sourceforge.net/
 net-commons/common-logging: A portable logging
abstraction for .NET
 https://github.com/net-commons/common-logging
 Xian's 學習筆記: Common.Logging
 http://blog.developer.idv.tw/2013/12/commonlogging.htm
l
13
Q&A
14
QUESTION & ANSWER
15

Common.logging

  • 1.
  • 2.
  • 3.
  • 4.
    INTRODUCTION  Provides asimple logging abstraction to switch between different logging implementations.  Support  Log4net  Nlog  Microsoft Enterprise Library logging  Microsoft Application Insights  Microsoft Event Tracing for Windows  Serilog 4
  • 5.
  • 6.
    GETTING STARTED Install Common.Logging and adapter pckagevia NuGet Register and configure Common.Logging Configure adapter log Write log with Common.Logging 6
  • 7.
    INSTALL COMMON.LOGGING ANDADAPTER PCKAGE VIA NUGET 7
  • 8.
    INSTALL COMMON.LOGGING ANDADAPTER PCKAGE VIA NUGET <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Common.Logging" version="3.3.1" targetFramework="net45" /> <package id="Common.Logging.Core" version="3.3.1" targetFramework="net45" /> <package id="Common.Logging.Log4Net1215" version="3.3.1" targetFramework="net45" /> <package id="log4net" version="2.0.5" targetFramework="net45" /> </packages> 8
  • 9.
    REGISTER AND CONFIGURE COMMON.LOGGING <?xmlversion="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.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net1215"> <!--<arg key="configType" value="INLINE" />--> <!--<arg key="configType" value="FILE" />--> <arg key="configType" value="FILE-WATCH" /> <arg key="configFile" value="~/log4net.config" /> </factoryAdapter> </logging> </common> </configuration> 9
  • 10.
    CONFIGURE ADAPTER LOG <?xmlversion="1.0" encoding="utf-8" ?> <log4net> <appender name="FullAppender" type="log4net.Appender.RollingFileAppender"> <file type="log4net.Util.PatternString" value="LogFull.log" /> <appendToFile value="true" /> <rollingStyle value="Composite" /> <datePattern value="yyyyMMdd" /> <maximumFileSize value="10MB" /> <maxSizeRollBackups value="-1" /> <CountDirection value="1" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date&#x9;[%thread]&#x9;%level&#x9;%logger&#x9;%identity&#x9;- %message%newline" /> </layout> </appender> <root> <level value="INFO" /> <appender-ref ref="FullAppender" /> </root> </log4net> 10
  • 11.
    WRITE LOG WITHCOMMON.LOGGING using Common.Logging; ... var logger = LogManager.GetLogger<Program>(); logger.Info("Hello World!"); ... 11
  • 12.
  • 13.
    REFERENCE  Common InfrastructureLibraries for .NET  http://netcommon.sourceforge.net/  net-commons/common-logging: A portable logging abstraction for .NET  https://github.com/net-commons/common-logging  Xian's 學習筆記: Common.Logging  http://blog.developer.idv.tw/2013/12/commonlogging.htm l 13
  • 14.
  • 15.