Code Monkey home page Code Monkey logo

teamslogger's Introduction

Teams Logger

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

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

teamslogger's People

Contributors

utsavized avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

demofan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.