Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 17th, 2013  |  syntax: None  |  size: 2.96 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <log4net>
  2. <root>
  3.   <level value="INFO" />
  4.   <appender-ref ref="AdoNetAppender" />
  5.   <appender-ref ref="EventLogAppender" />
  6. </root>
  7. <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
  8.   <bufferSize value="1" />
  9.   <reconnectonerror value="true" />
  10.   <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  11.   <connectionString value="Data Source=SQLHOTELL-FT,10433;Initial Catalog=BEKS;Integrated Security=True" />
  12.   <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception],[UserId]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, @userid)" />
  13.   <filter type="log4net.Filter.LevelRangeFilter">
  14.     <levelMin value="INFO" />
  15.     <levelMax value="FATAL" />
  16.   </filter>
  17.   <parameter>
  18.     <parameterName value="@log_date"/> <dbType value="DateTime"/> <layout type="log4net.Layout.RawTimeStampLayout"/>
  19.   </parameter>    
  20.   <parameter>      
  21.     <parameterName value="@thread"/> <dbType value="String"/> <size value="255"/> <layout type="log4net.Layout.PatternLayout">
  22.       <conversionPattern value="%thread"/>
  23.     </layout>
  24.   </parameter>    
  25.   <parameter>      
  26.     <parameterName value="@log_level"/> <dbType value="String"/> <size value="50"/> <layout type="log4net.Layout.PatternLayout">
  27.       <conversionPattern value="%level"/>
  28.     </layout>
  29.   </parameter>    
  30.   <parameter>        
  31.     <parameterName value="@logger"/> <dbType value="String"/> <size value="255"/> <layout type="log4net.Layout.PatternLayout">
  32.       <conversionPattern value="%logger"/>
  33.     </layout>
  34.  </parameter>      
  35.  <parameter>      
  36.     <parameterName value="@message"/> <dbType value="String"/> <size value="4000"/> <layout type="log4net.Layout.PatternLayout">
  37.       <conversionPattern value="%message"/>
  38.     </layout>
  39.   </parameter>      
  40.   <parameter>        
  41.     <parameterName value="@exception"/> <dbType value="String"/> <size value="2000"/> <layout type="log4net.Layout.ExceptionLayout"/>
  42.   </parameter>
  43.   <parameter>
  44. </appender>
  45. <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
  46.   <applicationName value="BeksWebInterface" />
  47.   <layout type="log4net.Layout.PatternLayout">
  48.     <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
  49.   </layout>
  50.   <filter type="log4net.Filter.LevelRangeFilter">
  51.     <levelMin value="FATAL" />
  52.     <levelMax value="FATAL" />
  53.   </filter>
  54. </appender>
  55.        
  56. public static class Log
  57. {
  58.     private static ILog log;
  59.  
  60.     public static void CreateLogEntry(string message)
  61.     {
  62.         try
  63.         {
  64.             log = LogManager.GetLogger(typeof(Log));
  65.  
  66.             log4net.Config.XmlConfigurator.Configure();
  67.  
  68.             log.Info(message);
  69.  
  70.         }
  71.         catch
  72.         {
  73.         }
  74.     }
  75. }
  76.        
  77. // Configure log4net
  78. var info = new FileInfo("myapp.log4net");
  79. log4net.Config.XmlConfigurator.Configure(info);
  80.  
  81. // get the logger
  82. var logger = LogManager.GetLogger(this.GetType());