
Using Visual Studio?
Install packages in Tools
-> Manage NuGet Packages...
.
Collect logs from C# applications.
Install Logtail
and NLog.Extension.Logging
packages:
dotnet add package Logtail
dotnet add package NLog.Extensions.Logging
Using Visual Studio?
Install packages in Tools
-> Manage NuGet Packages...
.
Set up NLog logging with Logtail. Save the following config as nlog.config
in your project root:
<?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"
internalLogLevel="Warn"
internalLogFile="internal.txt">
<extensions>
<add assembly="Logtail" />
</extensions>
<targets>
<target xsi:type="Logtail" name="logtail" sourceToken="$SOURCE_TOKEN" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="logtail" />
</rules>
</nlog>
Add the following configuration to your .csproj
file:
<ItemGroup>
<None Update="nlog.config" CopyToOutputDirectory="Always" />
</ItemGroup>
Using Visual Studio?
Right-click file nlog.config
-> Quick Properties
-> Copy to Output Directory
.
Use NLog logger as usual:
var logger = NLog.LogManager.GetCurrentClassLogger();
logger.Error("Something bad happened.");
logger.Info("Log message with structured logging. {object}", new {
item="Orange Soda",
price=100.00,
});
logger.Info("User has bought {item} for {price}.", "Orange Soda", 100.00);
You should see your logs in Logtail -> Live tail.
Find passed structured data under the context.properties
field.
.NET version 5 or higher is required.
Please let us know at hello@betterstack.com.
We're happy to help! ๐