TeamsLogger 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TeamsLogger --version 2.0.0
NuGet\Install-Package TeamsLogger -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TeamsLogger" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TeamsLogger --version 2.0.0
#r "nuget: TeamsLogger, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TeamsLogger as a Cake Addin
#addin nuget:?package=TeamsLogger&version=2.0.0

// Install TeamsLogger as a Cake Tool
#tool nuget:?package=TeamsLogger&version=2.0.0

Teams Logger

Rich logging for Microsoft Teams using HTTP POST to Teams Incoming Webhook Connector Github Project Link

Usage

Basic logger creation

var logger = new TeamsLogger.TeamsLogger(
	new TeamsWebhookClient("Your teams channel Uri"),
        new LoggerConfiguration { AutomaticallySetColor = true },
        "Module Name");
logger.LogMessage(LogSeverity.Info, "This is a simple log");

IoC Container logger registration

// This example uses Autofac
builder.Register(ctx =>
{
    var loggingUri = ConfigurationManager.AppSettings["TeamsLoggingUri"]; // Your teams channel uri
    var webhookClient = new TeamsWebhookClient(loggingUri);
    return new TeamsLogger.TeamsLogger(
	webhookClient,
        new LoggerConfiguration { AutomaticallySetColor = true },
        "Module Name");
}).As<ILogger>().SingleInstance();

logger.LogMessage(LogSeverity.Info, "This is a simple log");

Configuration

There is only one setting new LoggerConfiguration { AutomaticallySetColor = true } which dictates if message cards are automcatically colored based on severity of the message logged. User can always override this setting by supplying their own hex code.

Logging Concepts

Simple Logs

These create simple log messages and post to Teams right away. Each log message represents an individual message card.

// Color will set the color of the message card
public void LogMessage(LogSeverity severity, string message, string color = null);
public Task LogMessageAsync(LogSeverity severity, string message, string color = null);

Simple Log

Running Logs

Running logs help create rich log cards by aggregating multiple logs serially within your app, and eventually logging them all at once as a single Teams message card. Note: This only works if your app isn't distributing its logging. For distributed case, use simple logging.

For example:

var logger = new TeamsLogger.TeamsLogger(
	new TeamsWebhookClient("Your teams channel Uri"),
        new LoggerConfiguration { AutomaticallySetColor = true },
        "SomeModule");
	
// App begins running log aggregation
logger.BeginRunningLog("Begin logging");

// Logs app events
logger.AddLogToCurrentMessageCard(LogSeverity.Info, "Some event happened");
logger.AddLogToCurrentMessageCard(LogSeverity.Warn, "Not so good event happened");
logger.AddLogToCurrentMessageCard(LogSeverity.Error, "Bad event happened");

// some exception occurred, and was caught here
// Full log was uploaded to some url
logger.CreateNewExceptionMessageCard(e, "log url here", "Log");

// App continues
logger.AddLogToCurrentMessageCard(LogSeverity.Info, "Some event happened");
logger.AddLogToCurrentMessageCard(LogSeverity.Warn, "Not so good event happened");

_logger.PostRunningLog(); // Log is posted here, can use async

Simple Log

Product Compatible and additional computed target framework versions.
.NET Framework net47 is compatible.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 876 1/14/2019
2.0.0 632 12/11/2018
1.1.0 643 12/10/2018
1.0.0 648 12/10/2018