Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Custom NLog Target for sending log events via SMS using Twilio
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
namespace Twilio.Targets
{
[NLog.Targets.Target("Sms")]
public class Sms : NLog.Targets.TargetWithLayout
{
[Required]
public string AccountSid { get; set; }
[Required]
public string AuthToken { get; set; }
[Required]
public string From { get; set; }
[Required]
public string To { get; set; }
protected override void Write(NLog.LogEventInfo logEvent)
{
string logMessage = this.Layout.Render(logEvent);
SendTheMessageToTheRemoteHost(logMessage);
}
private void SendTheMessageToTheRemoteHost(string message)
{
string msg = (message.Length > 160) ? message.Substring(0, 160) : message;
var client = new TwilioRestClient(this.AccountSid, this.AuthToken);
client.SendSmsMessage(
this.From,
this.To,
msg
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.