farzadpanahi / nlog.gelflayout Goto Github PK
View Code? Open in Web Editor NEWGelf layout renderer for NLog
License: GNU Lesser General Public License v3.0
Gelf layout renderer for NLog
License: GNU Lesser General Public License v3.0
Can make message length FullMessageMaxLength and ShortMessageMaxLength configurable?
not hardcoded
Hello, I have a proposal.
I've found myself needing to differentiate between TRACE and DEBUG log leves. I know Syslog considers/maps these two into Severity 7 and since as per the Syslog standard we are locked in a 0-7 range for the severity level, I was thinking...
Could we have this layout print a levelName
property so we can differentiate between DEBUG and TRACE coming from NLog without messing around and potentially stepping outside of the Syslog standard? This of course could be set up to be optional and enabled by a configuration parameter just in case this field is not desired in the output.
Is this issue also affecting anyone else, or just me?
I wanted to propose it first, but I can implement this and submit a PR if you'd like.
The Syslog log levels Would map as they currently do:
Log Level | Syslog Mapping |
---|---|
Fatal | 2 |
Error | 3 |
Warn | 4 |
Info | 6 |
Debug | 7 |
Trace | 7 |
And then we'll have another property added called levelName
which will contain the log levels by name.
Log Level | String in the levelName field |
---|---|
Fatal | "Fatal" |
Error | "Error" |
Warn | "Warn" |
Info | "Info" |
Debug | "Debug" |
Trace | "Trace" |
Hi, how use variables in nlog.config for reuse layout ?
<?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">
<extensions>
<add assembly="NLog.Web.AspNetCore" />
<add assembly="NLog.Layouts.GelfLayout" />
</extensions>
<variable name="UdpElkEndpointUrl" value="udp://ip:12201"/>
<variable name='GelfMinimalLayout'>
<layout type='GelfLayout'>
<field name="lang" layout="dotnet" />
<field name="source" layout="${moduleNameForGelfSource}" />
<field name="facility" layout="${aspnet-environment}" />
<field name="UserName" layout="${username}"/>
<field name="longdate" layout="${longdate}" />
<field name="exception" layout="${exception:format=tostring}" />
<field name="stacktrace" layout="${stacktrace}" />
<field name="message" layout="${message}" />
</layout>
</variable>
<targets async="true">
<target xsi:type="Network" name="gelfUdp" address="${UdpElkEndpointUrl}" compress="GZip" compressMinBytes="1000">
<layout type="GelfLayout">
<layout type='${GelfMinimalLayout}' />
<field name="appdomain" layout="${appdomain}" />
<field name="environmentUser" layout="${environment-user}" />
<field name="machinename" layout="${machinename}" />
<field name="iisSiteName" layout="${iis-site-name}" />
<field name="windowsUser" layout="${windowsUser}" />
<field name="localIp" layout="${local-ip}" />
<field name="clientIpAddr" layout="${clientIpAddr}" />
<field name="requestIp" layout="${aspnet-request-ip}" />
<field name="requestUseragent" layout="${aspnet-request-useragent}" />
<field name="requestMethod" layout="${aspnet-request-method}" />
<field name="requestUrl" layout="${aspnet-request-url:IncludeHost=true:IncludePort=true:IncludeQueryString=true}" />
</layout>
<!--<layout type="${GelfMinimalLayout}">
<field name="appdomain" layout="${appdomain}" />
<field name="environmentUser" layout="${environment-user}" />
<field name="machinename" layout="${machinename}" />
<field name="iisSiteName" layout="${iis-site-name}" />
<field name="windowsUser" layout="${windowsUser}" />
<field name="localIp" layout="${local-ip}" />
<field name="clientIpAddr" layout="${clientIpAddr}" />
<field name="requestIp" layout="${aspnet-request-ip}" />
<field name="requestUseragent" layout="${aspnet-request-useragent}" />
<field name="requestMethod" layout="${aspnet-request-method}" />
<field name="requestUrl" layout="${aspnet-request-url:IncludeHost=true:IncludePort=true:IncludeQueryString=true}" />
</layout>-->
</target>
```
did not work
Hello,
In my project if i make this ( https://github.com/farzadpanahi/NLog.GelfLayout#sample-usage-with-custom-extra-fields ) example without extra fields, the Gelf Log works good!
But if I add extra fields, like this example ( https://github.com/farzadpanahi/NLog.GelfLayout#sample-usage-with-custom-extra-fields ), the program sends an error in runtime "Layout cannot be found: 'GelfLayout'"
Error details:
NLog.NLogConfigurationException
HResult=0x80131500
Message=Exception when parsing
(...)
ArgumentException: Layout cannot be found: 'GelfLayout'
Not sure if the NLog-Ordinal-Level-Numbers match Syslog-Severity-Numbers:
This is one source of Syslog-Severity-Numbers:
http://logging.paluch.biz/syslog-level-mapping.html
Level | NLog Ordinal | SysLog Severity |
---|---|---|
Trace | 0 | 7 |
Debug | 1 | 6 |
Info | 2 | 6 |
Warning | 3 | 4 |
Error | 4 | 3 |
Fatal | 5 | 2 |
Right now Info-Level-messages from NLog will become fatal-syslog-loglevel-messages.
@tomikiss I can make a PR for fixing this. If it makes sense?
We are having some issues when combining Nlog.GelfLayout with a Nlog Target wrapper like RandomizeGroup (https://github.com/NLog/NLog/wiki/RandomizeGroup-target) or RoundRobinGroup (https://github.com/NLog/NLog/wiki/RoundRobinGroup-target)
The entire Gelf message is missing from the output.
Example working config without wrapper:
<?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"
xmlns:haf="https://github.com/haf/NLog.RabbitMQ/raw/master/src/schemas/NLog.RabbitMQ.xsd"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >
<extensions>
<add assembly="NLog.Targets.RabbitMQ" />
<add assembly="NLog.Layouts.GelfLayout" />
</extensions>
<targets async="true">
<target name="RabbitMQTarget"
xsi:type="RabbitMQ"
hostname="x"
username="x"
password="x"
exchange="amq.direct"
topic="x"
passive="true"
vhost="nif-graylog"
durable="true"
useJSON="false"
layout="${gelf:facility=GelfLog}"
/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="RabbitMQTarget" />
</rules>
</nlog>
Example non-working config with wrapper:
<?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"
xmlns:haf="https://github.com/haf/NLog.RabbitMQ/raw/master/src/schemas/NLog.RabbitMQ.xsd"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >
<extensions>
<add assembly="NLog.Targets.RabbitMQ" />
<add assembly="NLog.Layouts.GelfLayout" />
</extensions>
<targets async="true">
<target name="RabbitMQTarget" xsi:type="RandomizeGroup">
<target xsi:type="RabbitMQ"
hostname="x"
username="x"
password="x"
exchange="amq.direct"
topic="x"
passive="true"
vhost="x"
durable="true"
useJSON="false"
layout="${gelf:_facility=GelfLog}" />
<target xsi:type="RabbitMQ"
hostname="x2"
username="x"
password="x"
exchange="amq.direct"
topic="x"
passive="true"
vhost="x"
durable="true"
useJSON="false"
layout="${gelf:facility=GelfLog}" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="RabbitMQTarget" />
</rules>
</nlog>
Any idea how to solve this?
Hi @farzadpanahi ,
Would you able to add my nuget.org user (tomikiss87) as a package owner to cut a new release? Thanks for your help.
When specifying a field with the name source and layout different from the lowercase word, udp gelf does not work
This is how it works
<field name="source" layout="producersrequestswebapicore" />
or
<field name="source" layout="producers-requests-web-api-core" />
or
<field name="source" layout="producers_requests_web_api_core" />
But no
<field name="source" layout="producersRequestsWebApiCore" />
or
<field name="source" layout="ProducersRequestsWebApiCore" />
asp core 3.1 web api
NLog.GelfLayout 1.4.0
....probably because source is used in index in elk
I know that NLog.GelfLayout was inspired by Gelf4NLog that is GPL ver. 3
But the GelfConverter.cs is now a complete rewrite by me, so there is no code-sharing or code-reuse anymore.
@tomikiss + @farzadpanahi Would you have any issues with changing the license from GPL ver. 3 to BSD-License or MIT-License ? (Have my permission to do it)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.