Using Visual Studio?
Install packages in Tools → Manage NuGet Packages....
Which .NET logger do you want to use to send logs to Better Stack?
Install NLog.Extensions.Logging and BetterStack.Logs.NLog packages:
Install packages in Tools → Manage NuGet Packages....
Set up NLog logging with Better Stack. Save the following config as nlog.config in your project root:
Add the following configuration to your .csproj file:
Right-click file nlog.config → Quick Properties → Copy to Output Directory.
Use NLog logger as usual:
You should see your logs in Better Stack → Live tail.
Find passed structured data under the context.properties field.
Install Serilog.Extensions.Logging and BetterStack.Logs.Serilog packages:
Install packages in Tools → Manage NuGet Packages....
Use Serilog logger with configured .WriteTo.BetterStack() sink:
You should see your logs in Better Stack → Live tail.
Find passed structured data under the properties field.
You can see example projects for both NLog and Serilog integration.
Fine-tune logging with more attributes of the BetterStack.Logs target in nlog.config.
Target attributes
Your Better Stack source token.
The ingesting URL of your source. Use https:// followed by the ingesting host listed in your source settings. The scheme can be left out since version 1.1.1.
NLog layout rendered into the message field, for example ${message}. Exceptions are sent in the exception field on their own.
Maximum number of logs sent in one batch. A batch is also kept under 5 MB, and a single log over 5 MB is dropped.
How often queued logs are sent.
How many times a batch is retried after its first attempt failed, before it's dropped. 0 sends each batch only once. Logs rejected by Better Stack, for example with a wrong token, are dropped right away and reported in NLog's internal log.
Maximum time flushing and closing the target wait for queued logs to be sent, so an unreachable endpoint doesn't hold up shutdown. 0 means no limit. Available since version 1.2.0.
Maximum number of logs waiting in memory to be sent. Logs over the limit are dropped. Available since version 1.2.0.
Sends the class, method, file, and line of the log call in context.runtime.
Sends GlobalDiagnosticsContext values in context.gdc.
Sends ScopeContext properties in context.properties. Use includeMdlc on NLog 4.
For logs to be sent to Better Stack reliably, Serilog must be properly closed by Log.CloseAndFlush(), even when the application ends unexpectedly. Log.CloseAndFlush() waits at most maxFlushTime, 30 seconds by default, for queued logs to be sent. For more information, see Lifecycle of Loggers in Serilog docs.
For more on Serilog configuration, see their official docs.
Fine-tune logging with more arguments of .WriteTo.BetterStack().
Sink options
Your Better Stack source token. Logs sent with a wrong token are dropped and reported in Serilog's SelfLog.
The ingesting URL of your source. Use https:// followed by the ingesting host listed in your source settings.
Formats the message field with a Serilog output template, for example [{Level:u3}] {SourceContext} - {Message:lj}. When it's not set or empty, message is the rendered log message. An invalid template throws when the logger is created. Available since version 1.3.0.
Culture-specific formatting of values in message, for example CultureInfo.InvariantCulture. Available since version 1.3.0.
Minimum level of logs sent to Better Stack. Ignored when levelSwitch is set.
Changes the minimum level of logs sent to Better Stack at runtime.
Maximum number of logs sent in one batch. A batch is also kept under 5 MB, and a single log over 5 MB is dropped.
Maximum time logs wait before they're sent to Better Stack.
Maximum size of logs waiting in memory to be sent. Logs over the limit are dropped. Use long.MaxValue for no limit, which was the default before version 1.4.0.
How many times a batch is retried after its first attempt failed, before it's dropped. 0 sends each batch only once. Available since version 1.4.0.
Maximum time Log.CloseAndFlush() waits for queued logs to be sent, so an unreachable endpoint doesn't hold up shutdown. TimeSpan.Zero means no limit. Available since version 1.4.0.
Configures the HTTP client, for example to use a proxy.
To configure the sink in appsettings.json instead, install the Serilog.Settings.Configuration package and read the configuration with .ReadFrom.Configuration():
Please let us know at hello@betterstack.com.
We're happy to help! 🙏
We use cookies to authenticate users, improve the product user experience, and for personalized ads. Learn more.