A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/NLog/NLog/wiki/WebService-target below:

WebService target · NLog/NLog Wiki · GitHub

Calls the specified web service on each log message.

Platforms Supported: All - Requires nuget-package NLog.Targets.WebService since NLog v6

<targets>
  <target xsi:type="WebService"
          name="String"
          url="System.Uri"
          encoding="Encoding"
          includeBOM="Nullable boolean"
          protocol="Enum"
          namespace="String"
          methodName="String"
          preAuthenticate="Boolean"
          userAgent="Layout">
    <parameter name="String" layout="Layout" parametertype="System.Type"/><!-- repeated -->
    <header name="String" layout="Layout"/><!-- repeated -->
  </target>
</targets>
HttpRequest Parameters Options

<parameter> defines a single parameter to be passed in the Http Request:

HttpRequest Headers Options

<header> defines a single Http-header to be included in Http Request:

NLog 4.6 allows override of Http-header SoapAction for Protocol Soap11

The web service must implement a method that accepts a number of string parameters.

<nlog>
    <targets>
        <target type='WebService'
                name='ws'
                url='http://localhost:1234/logme/post'
                protocol='HttpPost'
                encoding='UTF-8'>
            <parameter name='param1' type='System.String' layout='${message}'/> 
            <parameter name='param2' type='System.String' layout='${level}'/>
        </target>
    </targets>
    <rules>
      <logger name='*'writeTo='ws'></logger>
    </rules>
</nlog>
public class LogMeController : ApiController
{
    /// <summary>
    /// We need a complex type for modelbinding because 
    /// of content-type: "application/x-www-form-urlencoded" 
    /// in <see cref="WebServiceTarget"/>
    /// </summary>
    public class ComplexType
    {
        public string Param1 { get; set; }
        public string Param2 { get; set; }
    }
    
    /// <summary>
    /// Post
    /// </summary>
    public void Post([FromBody] ComplexType complexType)
    {
        //do something
    }
}
Example with JSON document

NLog v4.5 supports sending custom JSON document using a single nameless parameter, instead individual named parameters:

<target type="WebService"
   name="ws"
   url="http://localhost:1234/logme/jsonpost"
   protocol="JsonPost">
   <parameter name="">
      <layout xsi:type="JsonLayout">
         <attribute name='logger' layout='${logger}' />
         <attribute name='level' layout='${level}' />
         <attribute name="message" layout="${message}" />
      </layout>
   </parameter>
</target>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4