TeamsLogger 2.0.0
See the version list below for details.
dotnet add package TeamsLogger --version 2.0.0
NuGet\Install-Package TeamsLogger -Version 2.0.0
<PackageReference Include="TeamsLogger" Version="2.0.0" />
paket add TeamsLogger --version 2.0.0
#r "nuget: TeamsLogger, 2.0.0"
// 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);
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
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net47 is compatible. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
- Microsoft.Bot.Connector.Teams (>= 0.9.0)
- Newtonsoft.Json (>= 8.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.