<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kindeman</title>
    <description>The latest articles on DEV Community by Kindeman (@jedipi).</description>
    <link>https://dev.to/jedipi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F664711%2Fce690776-b20b-460a-80ca-8f5b52d5cb9a.jpeg</url>
      <title>DEV Community: Kindeman</title>
      <link>https://dev.to/jedipi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jedipi"/>
    <language>en</language>
    <item>
      <title>using NLog to send log message to MS Teams Channel via O365 Webhook Connector</title>
      <dc:creator>Kindeman</dc:creator>
      <pubDate>Mon, 19 Sep 2022 11:31:06 +0000</pubDate>
      <link>https://dev.to/jedipi/using-nlog-to-send-log-message-to-ms-teams-channel-via-o365-webhook-connector-2nlc</link>
      <guid>https://dev.to/jedipi/using-nlog-to-send-log-message-to-ms-teams-channel-via-o365-webhook-connector-2nlc</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I recently created a NLog target extension to write log message to Microsoft Teams Channel. &lt;br&gt;
&lt;a href="https://github.com/jedipi/NLog.Targets.MicrosoftTeams"&gt;NLog Targets for Microsoft Teams&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sending log messages to Microsoft Teams Channel is a good way to notify the development team or the service desk team if there is anything happened in your application. It helps proactively find out the issues sooner.&lt;/p&gt;

&lt;p&gt;Below are some benefits to send log message to MS Teams&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log message shows up in Teams instantly&lt;/li&gt;
&lt;li&gt;All team members get notified&lt;/li&gt;
&lt;li&gt;Log messages are searchable with Teams&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Let's Code
&lt;/h2&gt;

&lt;p&gt;First, let's create a console app using Visual Studio. I named the project as NLogTeams, and targeting .NET 6.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---Coq8Msb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rq8kdzyw83k9iptlzot7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---Coq8Msb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rq8kdzyw83k9iptlzot7.png" alt="NLog Targets for Microsoft Teams testing console app" width="880" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we need to install the necessary NuGet package. Just right click on the Solution and click on Manage NuGet Packages for Solution.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RFXAL_I1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xpue2yxthxf9fg6qda3v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RFXAL_I1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xpue2yxthxf9fg6qda3v.png" alt="nuget packages" width="756" height="581"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Type in &lt;code&gt;NLog.Targets.MicrosoftTeams&lt;/code&gt; in the search box, and install it. All the depended packages will be installed to the project as well.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--meCM8_z8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fdf6ilkr405bx3oagwq6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--meCM8_z8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fdf6ilkr405bx3oagwq6.png" alt="NLog Targets MicrosoftTeams NuGet Package" width="880" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's add a new xml file to the project, and name this new file as nlog.config.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vGcgpos0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vtbpkwk48zex68bwmrro.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vGcgpos0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vtbpkwk48zex68bwmrro.png" alt="nlog config" width="823" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open up the &lt;code&gt;nlog.config&lt;/code&gt; file, copy &amp;amp; paste the code below and save.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;
&amp;lt;nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xsi:schemaLocation="NLog NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogFile="internal.log"
      internalLogLevel="Off" &amp;gt;

  &amp;lt;!-- the targets to write to --&amp;gt;
  &amp;lt;targets&amp;gt;
    &amp;lt;!-- write logs to Microsoft Teams --&amp;gt;
    &amp;lt;target xsi:type="MicrosoftTeams, NLog.Targets.MicrosoftTeams"
            name="msTeams"
            WebhookUrl="Put 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}"
    /&amp;gt;
  &amp;lt;/targets&amp;gt;

  &amp;lt;!-- rules to map from logger name to target --&amp;gt;
  &amp;lt;rules&amp;gt;
    &amp;lt;logger name="*" minlevel="Trace" writeTo="msTeams" /&amp;gt;
  &amp;lt;/rules&amp;gt;
&amp;lt;/nlog&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You need to get the MS Teams Channel webhook URL. Please follow the Microsoft's instruction to create the incoming webhook in Teams. &lt;a href="https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you have the webhook URL, all you need to do is paste it into the &lt;code&gt;nlog.config&lt;/code&gt; file.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yzXIprTN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w652rh437328b4devdyz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yzXIprTN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w652rh437328b4devdyz.png" alt="Image description" width="880" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And make sure the &lt;code&gt;nlog.config&lt;/code&gt; file is always &lt;code&gt;Copy to Output Directory&lt;/code&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0EOAQ-6V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3821bsmoo0s2ifuve4d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0EOAQ-6V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3821bsmoo0s2ifuve4d.png" alt="Image description" width="401" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, you can now send log message to your Teams Channel. Let's test it by replacing the code in the &lt;code&gt;Program.cs&lt;/code&gt; with the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
using NLog;
MyClass.TestMethod();

public class MyClass
{
    static ILogger _logger = LogManager.GetCurrentClassLogger();
    public static void TestMethod()
    {
        Console.WriteLine("Hello World!");
        _logger.Info("Log to MS Teams channel like a boss");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. And the result would be like this.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qwM5om-x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0gjotsd14rvw68j4vpoi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qwM5om-x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0gjotsd14rvw68j4vpoi.png" alt="Image description" width="725" height="890"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Many businesses are leveraging Microsoft Teams for collaboration. I hope this helps you to integrate your application with Microsoft Teams to receive Error notification easily.&lt;/p&gt;

</description>
      <category>nlog</category>
      <category>teams</category>
      <category>microsoftteams</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Send log to MS Teams Channel with Nlog</title>
      <dc:creator>Kindeman</dc:creator>
      <pubDate>Sat, 10 Jul 2021 11:57:54 +0000</pubDate>
      <link>https://dev.to/jedipi/send-log-to-ms-teams-channel-with-nlog-1oa6</link>
      <guid>https://dev.to/jedipi/send-log-to-ms-teams-channel-with-nlog-1oa6</guid>
      <description>&lt;p&gt;I just created a NLog target that write log to Microsoft Teams channel via O365 Webhook Connector.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Support custom ApplicationName layout&lt;/li&gt;
&lt;li&gt;Support custom Teams message card title&lt;/li&gt;
&lt;li&gt;Support .Net Framework, .Net Core, .Net 5, and .Net Standard&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>showdev</category>
      <category>teams</category>
      <category>nlog</category>
      <category>csharp</category>
    </item>
  </channel>
</rss>
