-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted Twilio stuff to separate assembly. Switched license to GPL-…
…v3 or later. Updated docs.
- Loading branch information
1 parent
d8a9f38
commit 46efd01
Showing
9 changed files
with
155 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<AssemblyName>J4JSoftware.Logging.Twilio</AssemblyName> | ||
<RootNamespace>J4JSoftware.Logging</RootNamespace> | ||
<Authors>Mark A. Olbert</Authors> | ||
<Company>Jump for Joy Software</Company> | ||
<Product>J4JSoftware Logging Extensions for Serilog and Twilio</Product> | ||
<Description>Extends the J4JLogger library to support SMS logging via Twilio</Description> | ||
<Copyright>© Mark A. Olbert all rights reserved</Copyright> | ||
<PackageDescription>Extends the J4JLogger library to support SMS logging via Twilio</PackageDescription> | ||
<RepositoryUrl>https://github.com/markolbert/J4JLogger</RepositoryUrl> | ||
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<PackageIcon>Diego nuspec.png</PackageIcon> | ||
<RepositoryType>git</RepositoryType> | ||
<Version>1.0.0.0</Version> | ||
<AssemblyVersion>1.0.0.0</AssemblyVersion> | ||
<PackageReleaseNotes>Initial release as extension library</PackageReleaseNotes> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\J4JLogging\J4JLogging.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\Media\JumpForJoy\Diego nuspec.png"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Collections.Generic; | ||
using Serilog; | ||
using Serilog.Configuration; | ||
using Serilog.Formatting.Display; | ||
using Twilio; | ||
|
||
#pragma warning disable 8618 | ||
|
||
namespace J4JSoftware.Logging | ||
{ | ||
// Base class for containing the information needed to configure an instance of TwilioChannel | ||
public class TwilioConfig : ChannelConfig | ||
{ | ||
public string AccountSID { get; set; } | ||
public string AccountToken { get; set; } | ||
public string FromNumber { get; set; } | ||
public List<string> Recipients { get; set; } | ||
|
||
public override LoggerConfiguration Configure( LoggerSinkConfiguration sinkConfig ) | ||
{ | ||
TwilioClient.Init(AccountSID, AccountToken); | ||
|
||
return sinkConfig.Logger( lc => lc.Filter | ||
.ByIncludingOnly( "SendToSms" ) | ||
.WriteTo | ||
.Sms<TwilioSink>( | ||
new MessageTemplateTextFormatter( EnrichedMessageTemplate ), | ||
FromNumber, | ||
Recipients ) ); | ||
} | ||
|
||
public override bool IsValid | ||
{ | ||
get | ||
{ | ||
if( string.IsNullOrEmpty( AccountSID ) ) return false; | ||
if( string.IsNullOrEmpty( AccountToken ) ) return false; | ||
if( string.IsNullOrEmpty( FromNumber ) ) return false; | ||
|
||
return Recipients.Count != 0; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using Twilio.Rest.Api.V2010.Account; | ||
|
||
namespace J4JSoftware.Logging | ||
{ | ||
public class TwilioSink : SmsSink | ||
{ | ||
protected override void SendMessage( string logMessage ) | ||
{ | ||
foreach( var rn in RecipientNumbers ) | ||
{ | ||
try | ||
{ | ||
MessageResource.Create( body : logMessage, to : rn, @from : FromNumber ); | ||
} | ||
catch( Exception e ) | ||
{ | ||
throw new InvalidOperationException( | ||
$"Could not create Twilio message. Exception message was '{e.Message}'" ); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
### Change Log | ||
|
||
#### Changes to v3.2 | ||
I moved the Twilio SMS stuff into a separate assembly because it's not commonly used | ||
when logging and is large relative to the rest of the code base. | ||
|
||
The libraries are now licensed under the GNU GPL-v3.0 (or later) license. | ||
|
||
#### Changes to v3.1 | ||
I've modified, once again, how the output channels are configured when | ||
initializing the logger. | ||
|
||
You can set up a class implementing `IJ4JLoggerConfiguration` (e.g., | ||
`J4JLoggerConfiguration`) manually and add the channels you want to its | ||
`Channels` property. | ||
|
||
Or, if you're using the Net5 `IConfiguration` system you can implement | ||
an instance of `IChannelConfigProvider` and use the Autofac registration | ||
methods to do the work for you. See the [configuration section](docs/configuration.md) | ||
section for more details. | ||
|
||
#### Significant Changes to v3 | ||
- The libraries now target Net5 only, and have null checking enabled. | ||
- I consolidated all the default channels into the base J4JLogger assembly. Having | ||
them in separate assemblies complicated things. | ||
- The way log channels are configured was changed substantially (mostly because | ||
even the author found the earlier approach difficult to remember :)). | ||
- The `Autofac`-based setup approach was simplified. | ||
- To make logging possible before a program is fully set up a cached implementation | ||
of IJ4JLogger was added. The contents of the cache can be easily dumped into the actual | ||
logging system once it's established. | ||
|