Logging to webservice, add header to HTTP request.

884 views
Skip to first unread message

D.Ros

unread,
Apr 8, 2013, 12:15:32 PM4/8/13
to nlog-...@googlegroups.com
Hi,

I'm logging from a wp8 app into a REST webservice, to authenticate the devices I'm using some encrypted tokens, that I'm able to pass as part of the message, to this point everything works as expected, but what I would like to do now, is add the authentication data in the header of the POST HTTP request. Is this possible??


pd - Where can I see the change log of the latest version (NLog 2.0.1.2)?

Thanks
D.Rosado.


Kim Christensen

unread,
Apr 8, 2013, 12:22:52 PM4/8/13
to nlog-...@googlegroups.com

What target are you using?
The changelog can be found at http://github.com/NLog/NLog/issues?milestone=1&page=1&state=closed

D.Ros

unread,
Apr 9, 2013, 4:34:31 AM4/9/13
to nlog-...@googlegroups.com
Hi Kim,

This is my NLog.config

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true">

  <!--
  See http://nlog-project.org/wiki/Configuration_file
  for information on customizing logging rules and outputs.
   -->
  <targets async="true">
    <!-- each write attempt to be repeated 3 times, sleeping 5 second between attempts if first one fails. -->
    <target name="RetryingWrapper" xsi:type="RetryingWrapper" retryCount="3" retryDelayMilliseconds="5000">
      <target xsi:type="WebService" protocol="HttpPost" name="webService" url="http://***IPAddress***:8080/api/logs">
        <parameter name="appname" type="System.String" layout="My App Name"/>
        <parameter name="date" type="System.String" layout="${longdate}"/>
        <parameter name="level" type="System.String" layout="${level:upperCase=true}"/>
        <parameter name="message" type="System.String" layout="${message}"/>
        <parameter name="source" layout="${callsite:includeSourcePath=true}" />
        <parameter name="stacktrace" layout="${stacktrace:topFrames=10}" />
        <parameter name="exception" layout="${exception:format=ToString}"/>
        <parameter name="authKey" layout ="${event-context:item=AuthKey}"/> <---------- This is how I pass the authentication token now
      </target>
    </target>
  </targets>
 
  <rules>
    <!-- add your logging rules here -->
    <logger name="*" minlevel="Debug" writeTo="webService" final="true" />  
  </rules>
</nlog>


Regards,
D. Rosado

Kim Christensen

unread,
Apr 9, 2013, 5:18:14 PM4/9/13
to nlog-...@googlegroups.com
Unfortunately there are no way to do this, without creating a custom target, https://github.com/NLog/NLog/wiki/How-to-write-a-Target, possibly deriving from WebServiceTarget.

D.Ros

unread,
Apr 10, 2013, 4:12:15 AM4/10/13
to nlog-...@googlegroups.com

Ok, I'll give it a try. Thanks for the help.

Steven Guo

unread,
Oct 17, 2016, 1:26:34 PM10/17/16
to NLog-Users, diego...@gmail.com
Hey.D.Ros
I am working on the same one. Did you figure it out?

Thanks

Steven

Moe

unread,
Mar 28, 2017, 3:13:44 PM3/28/17
to NLog-Users, diego...@gmail.com
Hi D.ROS,

I'm also looking to do the same and I'm wondering if you figured it out.

Thanks,
Moe


On Wednesday, April 10, 2013 at 4:12:15 AM UTC-4, D.Ros wrote:

Rolf Kristensen

unread,
Aug 9, 2017, 3:31:56 PM8/9/17
to NLog-Users, diego...@gmail.com
Support for HTTP headers will be added with this PR

https://github.com/NLog/NLog/pull/1912

-Rolf
Reply all
Reply to author
Forward
0 new messages