VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#教程之基于Log4Net本地日志服务简单实现(2)

<!--<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender"> <bufferSize value="1" /> <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <connectionString value="DATABASE=Sample;SERVER=.\SQLEXPRESS;UID=sa;PWD=sasa;Connect Timeout=15;" /> <commandText value="INSERT INTO [Log4Net] ([Date],[Host],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @host, @thread, @log_level, @logger, @message, @exception)" /> <parameter> <parameterName value="@log_date" /> <dbType value="DateTime" /> <layout type="log4net.Layout.RawTimeStampLayout" /> </parameter> <parameter> <parameterName value="@thread" /> <dbType value="String" /> <size value="255" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%thread" /> </layout> </parameter> <parameter> <parameterName value="@host" /> <dbType value="String" /> <size value="50" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%property{log4net:HostName}" /> </layout> </parameter> <parameter> <parameterName value="@log_level" /> <dbType value="String" /> <size value="50" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%level" /> </layout> </parameter> <parameter> <parameterName value="@logger" /> <dbType value="String" /> <size value="255" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%logger" /> </layout> </parameter> <parameter> <parameterName value="@message" /> <dbType value="String" /> <size value="4000" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%message" /> </layout> </parameter> <parameter> <parameterName value="@exception" /> <dbType value="String" /> <size value="4000" /> <layout type="log4net.Layout.ExceptionLayout" /> </parameter> </appender>--> <!--使用ConsoleAppender方式记录日志按照日来记录日志--> <appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender"> <mapping> <level value="INFO" /> <foreColor value="White, HighIntensity" /> <backColor value="Green" /> </mapping> <mapping> <level value="DEBUG" /> <foreColor value="White, HighIntensity" /> <backColor value="Blue" /> </mapping> <mapping> <level value="WARN" /> <foreColor value="Yellow, HighIntensity" /> <backColor value="Purple" /> </mapping> <mapping> <level value="ERROR" /> <foreColor value="Yellow, HighIntensity" /> <backColor value="Red" /> </mapping> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="---------------------------------------------------%newline发生时间:%date %newline事件级别:%-5level%newline事件来源:%logger%newline事件行号:%line%newline日志内容:%message%newline" /> </layout> </appender> <appender name="UdpAppender" type="log4net.Appender.UdpAppender"> <remoteAddress value="127.0.0.1" /> <remotePort value="7071" /> <layout type="log4net.Layout.XmlLayoutSchemaLog4j" /> </appender> <root> <appender-ref ref="UdpAppender" /> </root> </log4net> </configuration>

怎么使用#


	
Copy
private IKernel _kernel = null; private ILogService _logService = null; [TestInitialize] public void SetUp() { _kernel = new StandardKernel(new LogModule()); Assert.IsNotNull(_kernel); _logService = _kernel.Get<ILogService>(); } [TestMethod()] public void DebugTest() { _logService.Debug("DebugTest"); }

结语#

  1. 整个实现很简单,就是业务或者功能不依赖具体实现类,这也是开发中最基本原则;
  2. 小弟不才,大佬轻拍;

作者:YanZhiwei

出处:https://www.cnblogs.com/MeetYan/p/10687029.html

本站使用「署名 4.0 国际」创作共享协议,转载请在文章明显位置注明作者及出处。



相关教程
关于我们--广告服务--免责声明--本站帮助-友情链接--版权声明--联系我们       黑ICP备07002182号