Skip to content

Commit

Permalink
Extracted Twilio stuff to separate assembly. Switched license to GPL-…
Browse files Browse the repository at this point in the history
…v3 or later. Updated docs.
  • Loading branch information
markolbert committed Feb 1, 2021
1 parent d8a9f38 commit 46efd01
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 28 deletions.
7 changes: 7 additions & 0 deletions J4JLogging.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gitdoc", "gitdoc", "{33976A4C-64BD-4142-BF64-DA4714E000AA}"
ProjectSection(SolutionItems) = preProject
docs\autofac.md = docs\autofac.md
docs\changes.md = docs\changes.md
docs\channel.md = docs\channel.md
docs\configuration.md = docs\configuration.md
docs\elements.md = docs\elements.md
Expand All @@ -31,6 +32,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmbeddedFileExample", "exam
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "J4JLoggingTests", "J4JLoggingTests\J4JLoggingTests.csproj", "{E724D950-8108-4B98-8063-1C30CEEDE432}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "J4JLoggingTwilio", "J4JLoggingTwilio\J4JLoggingTwilio.csproj", "{C21270BA-083B-4054-8143-8FA17520D918}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -61,6 +64,10 @@ Global
{E724D950-8108-4B98-8063-1C30CEEDE432}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E724D950-8108-4B98-8063-1C30CEEDE432}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E724D950-8108-4B98-8063-1C30CEEDE432}.Release|Any CPU.Build.0 = Release|Any CPU
{C21270BA-083B-4054-8143-8FA17520D918}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C21270BA-083B-4054-8143-8FA17520D918}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C21270BA-083B-4054-8143-8FA17520D918}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C21270BA-083B-4054-8143-8FA17520D918}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
10 changes: 6 additions & 4 deletions J4JLogging/J4JLogging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@
<Copyright>© Mark A. Olbert all rights reserved</Copyright>
<PackageDescription>Wrapper for Serilog ILogger to provide source code information and enable SMS logging</PackageDescription>
<RepositoryUrl>https://github.com/markolbert/J4JLogger</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageIcon>Diego nuspec.png</PackageIcon>
<RepositoryType>git</RepositoryType>
<Version>3.1.0.0</Version>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
<PackageReleaseNotes>revised channel configuration from IConfiguration system</PackageReleaseNotes>
<Version>3.2.0.0</Version>
<AssemblyVersion>3.2.0.0</AssemblyVersion>
<PackageReleaseNotes>extracted Twilio stuff into standalone library</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
<Compile Remove="docs\**" />
<EmbeddedResource Remove="docs\**" />
<None Remove="docs\**" />
<Compile Remove="channels\TwilioConfig.cs" />
<Compile Remove="configuration\channels\ChannelConfigProviderBase.cs" />
<Compile Remove="configuration\channels\StaticChannelConfigProvider.cs" />
<Compile Remove="sinks\TwilioSink.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions J4JLoggingTests/J4JLoggingTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

<ItemGroup>
<ProjectReference Include="..\AutoFacJ4JLogging\AutofacJ4JLogging.csproj" />
<ProjectReference Include="..\J4JLoggingTwilio\J4JLoggingTwilio.csproj" />
<ProjectReference Include="..\J4JLogging\J4JLogging.csproj" />
</ItemGroup>

Expand Down
35 changes: 35 additions & 0 deletions J4JLoggingTwilio/J4JLoggingTwilio.csproj
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>
44 changes: 44 additions & 0 deletions J4JLoggingTwilio/TwilioConfig.cs
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;
}
}
}
}
24 changes: 24 additions & 0 deletions J4JLoggingTwilio/TwilioSink.cs
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}'" );
}
}
}
}
}
30 changes: 6 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
A Net 5.0 library which wraps [Serilog's ILogger](https://github.com/serilog/serilog) and extends it by
reporting source code information.

Licensed under GNU GPL-v3.0. See the [license file](license.md) for details.

[![Nuget](https://img.shields.io/nuget/v/J4JSoftware.Logging?style=flat-square)](https://www.nuget.org/packages/J4JSoftware.Logging/)


Expand Down Expand Up @@ -81,30 +83,9 @@ Contents of logConfig.json:
}
}
```
### 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.

### 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.


See the [change log](docs/changes.md) for information on changes.

### Important Note
**There is one important difference in how you call the logging methods
from the Serilog standard.**
Expand All @@ -126,6 +107,7 @@ specifications for the arguments necessary when strings are referenced by the me

### Table of Contents

- [Change Log](docs/changes.md)
- [Goal and Concept](docs/goal-concept.md)
- [Terminology](docs/terminology.md)
- [Usage](docs/usage.md)
Expand Down
Empty file added TextFile1.txt
Empty file.
32 changes: 32 additions & 0 deletions docs/changes.md
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.

0 comments on commit 46efd01

Please sign in to comment.