Skip to the content.

NuGet version (NLog.Targets.MicrosoftTeams) Build Status .NET GitHub NuGet downloads HitCount

Build History

Build History

Stargazers & Forkers

Stargazers repo roster for @jedipi/NLog.Targets.MicrosoftTeams Forkers repo roster for @jedipi/NLog.Targets.MicrosoftTeams

NLog.Targets.MicrosoftTeams


A NLog target that write log to Microsoft Teams channel via O365 Webhook Connector.

For more Information about webhhoks in Teams read:

Output

Example NLog.Targets.MicrosoftTeams output

Getting Started

Installation

Add the NLog.Targets.MicrosoftTeams package from nuget to your project.

PM> Install-Package NLog.Targets.MicrosoftTeams


Usage

<!-- Example app.config -->
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
  <appSettings>
    <add key="Logging.TeamsUrl" value="Your Teams Channel Webhook" />
  </appSettings>
</configuration>

NLog.config

<!-- Example for getting Webhook URL from app.config -->
<!-- write logs to Microsoft Teams -->
<target xsi:type="MicrosoftTeams, NLog.Targets.MicrosoftTeams" 
         name="msTeams" 
         WebhookUrl="${appsetting:name=Logging.TeamsUrl}"          
         ApplicationName="Your Application Name"
         CardTitle="Title - ${level:uppercase=true}: ${date} - [${logger}]"
         layout="[${level:uppercase=true}] ${logger} - ${message} ${all-event-properties}"
    />

<!-- Example for getting Webhook URL from appsetting.json -->
<!-- write logs to Microsoft Teams -->
<target xsi:type="MicrosoftTeams, NLog.Targets.MicrosoftTeams" 
         name="msTeams" 
         WebhookUrl="${configsetting:name=Logging.TeamsUrl}"          
         ApplicationName="Your Application Name"
         CardTitle="Title - ${level:uppercase=true}: ${date} - [${logger}]"
         layout="[${level:uppercase=true}] ${logger} - ${message} ${all-event-properties}"
    />

<!-- Example for setting Webhook URL inside nlog.conf -->
<!-- write logs to Microsoft Teams -->
<target xsi:type="MicrosoftTeams, NLog.Targets.MicrosoftTeams" 
         name="msTeams" 
         WebhookUrl="Your Teams Webhook URL here"          
         ApplicationName="Your Application Name"
         CardTitle="Title - ${level:uppercase=true}: ${date} - [${logger}]"
         layout="[${level:uppercase=true}] ${logger} - ${message} ${all-event-properties}"
    />

Support

If you’ve got value from any of the content which I have created, then I would also very much appreciate your support by buying me a beer.

buy me a beer