title: Using log4net over web service
body: <p>I want to write a web service that is able send log data to syslog server. </p>
  
  <p>Architecture is like this:</p>
  
  <pre><code>Client ---&gt; Webservice ----&gt; syslog server
  </code></pre>
  
  <p>Clients call the web service like this: </p>
  
  <pre><code>ServiceReference1.SysLogServiceClient clt = new ServiceReference1.SysLogServiceClient();
  ServiceReference1.ClsSysLog temp = new ServiceReference1.ClsSysLog();
  temp.date= DateTime.Now;
  temp.time = DateTime.Now;
  temp.processtype= "test";
  temp.user= "testuser";
  temp.application = "testapp";
  bool result = clt.SendSysLog(temp);
  </code></pre>
  
  <p>Web service has a class and a function:</p>
  
  <p>class: </p>
  
  <pre><code>[DataContract]
  public class ClsSysLog
  {
      [DataMember]
      public DateTime date{ get; set; }
  
      [DataMember]
      public DateTime time { get; set; }
  
      [DataMember]
      public string processtype { get; set; }
  
      [DataMember]
      public string user { get; set; }
  
      [DataMember]
      public string application { get; set; }    
  
  }
  </code></pre>
  
  <p>Function:</p>
  
  <pre><code>private static readonly ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  
  public bool SendSysLog(ClsSysLog SysLogItem)
  {
      try
      {
          //date|time|processtype|user|application
          string msg = String.Format("{0:yyyy-MM-dd}|{1:HH:mm:ss}|{2}|{3}|{4}|{5}|{6}", SysLogItem.date, SysLogItem.time, SysLogItem.processtype, SysLogItem.user, SysLogItem.application);
          Exception tempExt = new Exception();
          log.Info(msg, tempExt);
          return true;
      }
      catch (Exception ex)
      {
          return false;
      }
  }
  </code></pre>
  
  <p>Lastly the web service configuration is: </p>
  
  <pre><code>&lt;log4net&gt;
      &lt;appender name="RemoteSyslogAppender" type="log4net.Appender.RemoteSyslogAppender"&gt;
        &lt;facility value="qradar" /&gt;
        &lt;identity value=" %date{yyyy-MM-ddTHH:mm:ss.ffffffzzz} %P{log4net:HostName} %P{app}" /&gt;
        &lt;RemoteAddress value="192.168.1.55" /&gt;
        &lt;layout type="log4net.Layout.PatternLayout" value="   %P{pid}:%logger %m%n"   /&gt;
        &lt;RemotePort value="514" /&gt;
      &lt;/appender&gt;
      &lt;root&gt;
        &lt;level value="ALL" /&gt;
        &lt;appender-ref ref="RealtimeMonitoringAppender" /&gt;
      &lt;/root&gt;
    &lt;/log4net&gt;
  </code></pre>
  
  <p>I do not know what the syslog server is doing, but by network sniffing tool, I see that it has no packet from 514 port.</p>
  
  <p>Exception from the <code>log.Info(msg, tempExt)</code> function is </p>
  
  <blockquote>
    <p>System.Exception: Exception of type 'System.Exception' was thrown.</p>
  </blockquote>
  
  <p>I cannot send syslog data to server by web service.</p>