rollbar / Rollbar.NET

Rollbar for .NET
https://docs.rollbar.com/docs/dotnet
MIT License
65 stars 44 forks source link

NLog plugin: report custom properties like application name #639

Open ygavrishov opened 1 year ago

ygavrishov commented 1 year ago

Hi team! I did not find a very important possibility - to attach custom properties to error reports. The most typical case is to attach the application name. We have multiple applications that report to the same Rollbar project and only stack trace can help to distinguish applications.

snakefoot commented 1 year ago

The NLog RollbarTarget inherits from TargetWithContext that support context-capture.

Example:

<?xml version="1.0" encoding="utf-8" ?>
<nlog throwConfigExceptions="true">

  <extensions>
    <add assembly="Rollbar.PlugIns.NLog"/>
  </extensions>

  <targets>
    <target name="logrollbar" type="Rollbar.PlugIns.NLog">
      <contextproperty name="HostName" layout="${machinename}" />
      <contextproperty name="ApplicationName" layout="MySuperApplication" />
      <contextproperty name="ProcessName" layout="${processname}" />
      <contextproperty name="AppDomainName" layout="${appdomain:cached=true:format=\{1\}}" />
    </target>
  </targets>

  <rules>
    <logger name="*" minlevel="Info" writeTo="logrollbar" />
  </rules>
</nlog>

See also: https://github.com/rollbar/Rollbar.NET/tree/master/Samples/Sample.PlugIns.NLog