Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 1.99 KB

readme.md

File metadata and controls

44 lines (29 loc) · 1.99 KB

Twilio Sink for J4JLogger


As of 2023 April 4 I am no longer developing this library.

The reason is simple: I learned more about how Serilog works and realized there was a much easier way of implementing the same functionality :).

Take a look at J4JLoggerEnhancements for a new, slimmer approach for doing what J4JLogging does.


This library provides a Serilog sink which J4JLogger can use to send SMS messages via Twilio.

See the github documentation for J4JLogger for more information.

Licensed under GNU GPL-v3.0. See the license file for details.

See the change log for a history of changes to the library.

Adding a TwilioSink

Adding a TwilioSink to J4JLoggerConfiguration is straightforward. This example assumes the required configuration information is contained in a user-secrets cache since I don't want my Twilio credentials available publicly. It also does not contain any recipient phone numbers so it will not work as shown:

var configBuilder = new ConfigurationBuilder();

var config = configBuilder
    .AddUserSecrets<LoggingTests>()
    .Build();

var twilioConfig = new TwilioConfiguration
{
    AccountSID = config.GetValue<string>( "twilio:AccountSID" ),
    AccountToken = config.GetValue<string>( "twilio:AccountToken" ),
    FromNumber = config.GetValue<string>( "twilio:FromNumber" ),
    Recipients = new List<string> { /* recipient phone numbers go here */ }
};

var loggerConfig = new J4JLoggerConfiguration( FilePathTrimmer )
    .AddTwilio( twilioConfig );

You can supply a Serilog output template string to the sink but by default it uses one that contains both calling context information (e.g., calling method name) and the placeholder required to trigger the sending of SMS messages.