WebServiceTarget Class |
Namespace: NLog.Targets
The WebServiceTarget type exposes the following members.
Name | Description | |
---|---|---|
WebServiceTarget |
Initializes a new instance of the WebServiceTarget class.
| |
WebServiceTarget(String) |
Initializes a new instance of the WebServiceTarget class.
|
Name | Description | |
---|---|---|
Encoding |
Gets or sets the encoding.
| |
EscapeDataRfc3986 |
Gets or sets a value whether escaping be done according to Rfc3986 (Supports Internationalized Resource Identifiers - IRIs)
| |
Headers |
Gets the array of parameters to be passed.
| |
IncludeBOM |
Should we include the BOM (Byte-order-mark) for UTF? Influences the Encoding property.
This will only work for UTF-8.
| |
MethodName |
Gets or sets the Web service method name. Only used with Soap.
| |
Name |
Gets or sets the name of the target.
(Inherited from Target.) | |
Namespace |
Gets or sets the Web service namespace. Only used with Soap.
| |
Parameters |
Gets the array of parameters to be passed.
(Inherited from MethodCallTargetBase.) | |
PreAuthenticate |
Indicates whether to pre-authenticate the HttpWebRequest (Requires 'Authorization' in Headers parameters)
| |
Protocol |
Gets or sets the protocol to be used when calling web service.
| |
ProxyAddress |
Gets or sets the custom proxy address, include port separated by a colon
| |
ProxyType |
Gets or sets the proxy configuration when calling web service
| |
Url |
Gets or sets the web service URL.
| |
UserAgent |
Gets or sets the value of the User-agent HTTP header.
| |
XmlRoot | ||
XmlRootNamespace |
Name | Description | |
---|---|---|
Dispose |
Closes the target.
(Inherited from Target.) | |
Flush |
Flush any pending log messages (in case of asynchronous targets).
(Inherited from Target.) | |
PrecalculateVolatileLayouts |
Calls the Precalculate(LogEventInfo) on each volatile layout
used by this target.
This method won't prerender if all layouts in this target are thread-agnostic.
(Inherited from Target.) | |
ToString | Returns a string that represents the current object. (Inherited from Target.) | |
WriteAsyncLogEvent |
Writes the log to the target.
(Inherited from Target.) | |
WriteAsyncLogEvents(AsyncLogEventInfo) |
Writes the array of log events.
(Inherited from Target.) | |
WriteAsyncLogEvents(IListAsyncLogEventInfo) |
Writes the array of log events.
(Inherited from Target.) |
To set up the target in the configuration file, use the following syntax:
1<?xml version="1.0" ?> 2<nlog autoReload="true" 3 xmlns="http://www.nlog-project.org/schemas/NLog.xsd" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 5 <targets> 6 <target name="ws" xsi:type="WebService" namespace="http://www.nlog-project.org/example" protocol="Soap11" methodName="HelloWorld" url="http://localhost:2648/Service1.asmx"> 7 <parameter name="n1" parameterType="System.String" layout="${message}"/> 8 <parameter name="n2" parameterType="System.String" layout="${logger}"/> 9 <parameter name="n3" parameterType="System.String" layout="${level}"/> 10 </target> 11 </targets> 12 13 <rules> 14 <logger name="*" writeTo="ws" /> 15 </rules> 16</nlog>
To set up the log target programmatically use code like this:
1using NLog; 2using NLog.Targets; 3 4class Example 5{ 6 static void Main(string[] args) 7 { 8 WebServiceTarget target = new WebServiceTarget(); 9 target.Url = "http://localhost:2648/Service1.asmx"; 10 target.MethodName = "HelloWorld"; 11 target.Namespace = "http://www.nlog-project.org/example"; 12 target.Protocol = WebServiceTarget.WebServiceProtocol.Soap11; 13 14 target.Parameters.Add(new MethodCallParameter("n1", "${message}")); 15 target.Parameters.Add(new MethodCallParameter("n2", "${logger}")); 16 target.Parameters.Add(new MethodCallParameter("n3", "${level}")); 17 18 NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug); 19 20 Logger logger = LogManager.GetLogger("Example"); 21 logger.Trace("log message 1"); 22 logger.Debug("log message 2"); 23 logger.Info("log message 3"); 24 logger.Warn("log message 4"); 25 logger.Error("log message 5"); 26 logger.Fatal("log message 6"); 27 } 28}
The example web service that works with this example is shown below
1using System; 2using System.Data; 3using System.Web; 4using System.Collections; 5using System.Web.Services; 6using System.Web.Services.Protocols; 7using System.ComponentModel; 8 9namespace WebService1 10{ 11 [WebService(Namespace = "http://www.nlog-project.org/example")] 12 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 13 [ToolboxItem(false)] 14 public class Service1 : System.Web.Services.WebService 15 { 16 [WebMethod] 17 public void HelloWorld(string n1, string n2, string n3) 18 { 19 HttpContext.Current.Trace.Write("n1 " + n1); 20 HttpContext.Current.Trace.Write("n2 " + n2); 21 HttpContext.Current.Trace.Write("n3 " + n3); 22 } 23 } 24}