- Notifications
You must be signed in to change notification settings - Fork16
DarekDan/NLog.Targets.HTTP
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
2024.05.10 - With the introduction of NLog 5.0WebServiceTargetthis project will be heading towards becoming an archive.
NLog.Targets.HTTP is an HTTP POST target for NLog.When combined with JSON formatter it can be used to send events to aninstance of Splunk and other HTTP based collectors.
This target is inherently asynchronous, with performance on par or better than with the AsyncWrapper.Remember to Flush and to give it enough time to complete.
Note that theasync="true"
attribute applied to<targets >
willdiscard by default.
Add the library as an extension to nlog:
<nlogxmlns="http://www.nlog-project.org/schemas/NLog.xsd"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <extensions> <addassembly="NLog.Targets.Http" /> </extensions> <targets> ...
Listed below are available configuration parameters with their default values (where applicable)
<targetname='target name'type='HTTP'URL='protocol://server:port/path'Method='POST'Authorization='phrase token'BatchSize='1'MaxQueueSize='2147483647'IgnoreSslErrors='true'FlushBeforeShutdown='true'ContentType='application/json'Accept='application/json'DefaultConnectionLimit='2'Expect100Continue='false'UseNagleAlgorithm='true'ConnectTimeout='30000'InMemoryCompression='true'ProxyUrl=''ProxyUser=''ProxyPassword='' ><!-- optional additional HTTP Headers--> <headername='key'value='value'/><!-- additional headers--><!-- layout element--></target>
The URL (Layout
element) to send messages to (mandatory).
HTTP method to use (GET,POST).
The Authorization Header value to pass.
Number of messages to be sent together in one call.
If set totrue
, messages will be packaged as JSON Array instead of beingseparated withEnvironment.NewLine
character. Default isfalse
.
Maximum number of messages awaiting to be send. Please note, that if this value is set too low, the logger might be blocking.
Some SSL certificates might be invalid or not-trusted.
Force all messages to be delivered before shutting down. Note that by design .Net apps are limited to about 2 seconds to shutdown.
Make sure you leverageLogManager.Flush(TimeSpan.FromHours(24))
in most extreme scenarios.
HTTP ContentType Header value. Default isapplication/json
.
HTTP Accept Header value. Default isapplication/json
.
How many connections might be used at the same time. Changes ServicePointManager.DefaultConnectionLimit, which might affect other parts of your system.Performance improvement was noticeable even with 16 connections, but your application might require more for other functionality. Use with caution.
Seethis article.
The Nagle algorithm is used to buffer small packets of data and transmit them as a single packet. This process, referred to as "nagling," is widely usedbecause it reduces the number of packets transmitted and lowers the overhead per packet. The Nagle algorithm is fully described in IETF RFC 896.
How long should the client wait to connect (default is30 seconds).
Reduces the amount of memory consumed at the expense of increased CPU usage. Significant performance improvement can be achieved by using default offalse
.
Designates a proxy server to use. Must include protocol (http|https) and port.It is aLayout
element so can be dynamic.
If proxy authentication is needed, you can specify it with a domain prefix, i.e. DOMAIN\USER.
Password to use for proxy authentication.
Additional HTTP Headers can be specified by adding multiple<header name='..' value='..'/>
elements.Elements with a blankname
orvalue
will not be included.
The "Unix Time" renderer supportsuniversalTime
option (boolean), just like the date renderer does.
<attributename='unixutc'layout='${unixtime:universalTime=true}' />
<?xml version="1.0" encoding="utf-8" ?><nlogxmlns="http://www.nlog-project.org/schemas/NLog.xsd"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <targets> <targetname='splunk'type='HTTP'URL='https://localhost:8088/services/collector/event'Authorization='Splunk d758f3fa-740f-4bb7-96be-3da4128708bc'BatchSize='100'> <layouttype='JsonLayout'> <attributename='sourcetype'layout='_json' /> <attributename='host'layout='${machinename}' /> <attributename='event'encode='false'> <layouttype='JsonLayout'> <attributename='level'layout='${level:upperCase=true}' /> <attributename='source'layout='${logger}' /> <attributename='thread'layout='${threadid}' /> <attributename='message'layout='${message}' /> <attributename='utc'layout='${date:universalTime=true:format=yyyy-MM-dd HH\:mm\:ss.fff}' /> </layout> </attribute> </layout> </target> </targets> <rules> <loggername="*"minlevel="Debug"writeTo="splunk" /> </rules></nlog>
On a Lenovo Xeon E3-1505M v6 powered laptop with 64GB of RAM and 3GB/s NVMe storage,this HTTP target was able to consistenlty accept about 125,000 messages per second,and 62,500 per second received and processed by local Dockerized Splunk Enterpise 8.2.4.Please note, that these stats depend heavily on the message size, batch size, and amount of bytesthat can be submitted in a single POST message.
docker pull splunk/splunk:latestdocker run -d -p 8000:8000 -p 8088:8088 -e"SPLUNK_START_ARGS=--accept-license" -e"SPLUNK_PASSWORD=Pass@W0rd" --name splunk splunk/splunk:latest
After a few moments, depeneding on your systems capacity,login to Splunk athttp://localhost:8000/ withadmin
andPass@W0rd
.The HttpEventCollector (HEC) will listen on port 8088 once created fromSettings - Data Inputs menu option.
About
An HTTP target for NLog
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.