Skip to content

Commit

Permalink
Merge pull request #19 from jonas-merkle/develop
Browse files Browse the repository at this point in the history
fixed naming again
  • Loading branch information
jonas-merkle authored Nov 16, 2020
2 parents 28866fe + 6ac96fd commit 1083ba9
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 48 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ A basic Slack Sink for the Serilog framework.
| | |
|----------------------:|-----------------------|
| Nuget Package Version | [![Nuget Version](https://img.shields.io/nuget/v/Serilog.Sinks.SlackWebHook?style=flat-square)](https://www.nuget.org/packages/Serilog.Sinks.SlackWebHook/) |
| nuget.org Deployment | [![nuget.org Deployment](https://img.shields.io/azure-devops/release/jonas-merkle/09454b63-c969-4591-aa24-ea8867d031bd/1/2?style=flat-square)](https://dev.azure.com/jonas-merkle/serilog-sinks-slackwebhook/_release?view=all&_a=releases&definitionId=1) |
| Build Status Master | [![Build Status Master](https://img.shields.io/azure-devops/build/jonas-merkle/serilog-sinks-slackwebhook/3/master?style=flat-square)](https://dev.azure.com/jonas-merkle/serilog-sinks-slackwebhook/_build/latest?definitionId=3) |
| Build Status Develop | [![Build status Develop](https://img.shields.io/azure-devops/build/jonas-merkle/serilog-sinks-slackwebhook/4/develop?style=flat-square)](https://dev.azure.com/jonas-merkle/serilog-sinks-slackwebhook/_build/latest?definitionId=4) |
| Test Status Master | [![Test Status Master](https://img.shields.io/azure-devops/tests/jonas-merkle/serilog-sinks-slackwebhook/3?compact_message&style=flat-square)](https://dev.azure.com/jonas-merkle/serilog-sinks-slackwebhook/_test/analytics?definitionId=3&contextType=build) |
| Test Status Develop | [![Test Status Master](https://img.shields.io/azure-devops/tests/jonas-merkle/serilog-sinks-slackwebhook/4?compact_message&style=flat-square)](https://dev.azure.com/jonas-merkle/serilog-sinks-slackwebhook/_test/analytics?definitionId=4&contextType=build) |
| nuget.org Deployment | [![nuget.org Deployment](https://img.shields.io/azure-devops/release/jonas-merkle/09454b63-c969-4591-aa24-ea8867d031bd/1/2?style=flat-square)](https://dev.azure.com/jonas-merkle/Serilog.Sinks.SlackWebHook/_release?view=all&_a=releases&definitionId=1) |
| Build Status Master | [![Build Status Master](https://img.shields.io/azure-devops/build/jonas-merkle/Serilog.Sinks.SlackWebHook/3/master?style=flat-square)](https://dev.azure.com/jonas-merkle/Serilog.Sinks.SlackWebHook/_build/latest?definitionId=3) |
| Build Status Develop | [![Build status Develop](https://img.shields.io/azure-devops/build/jonas-merkle/Serilog.Sinks.SlackWebHook/4/develop?style=flat-square)](https://dev.azure.com/jonas-merkle/Serilog.Sinks.SlackWebHook/_build/latest?definitionId=4) |
| Test Status Master | [![Test Status Master](https://img.shields.io/azure-devops/tests/jonas-merkle/Serilog.Sinks.SlackWebHook/3?compact_message&style=flat-square)](https://dev.azure.com/jonas-merkle/Serilog.Sinks.SlackWebHook/_test/analytics?definitionId=3&contextType=build) |
| Test Status Develop | [![Test Status Master](https://img.shields.io/azure-devops/tests/jonas-merkle/Serilog.Sinks.SlackWebHook/4?compact_message&style=flat-square)](https://dev.azure.com/jonas-merkle/Serilog.Sinks.SlackWebHook/_test/analytics?definitionId=4&contextType=build) |
| Sonar Code Quality | [![Sonar Code Quality](https://img.shields.io/sonar/quality_gate/jonas-merkle_serilog-sinks-slackwebhook?server=https%3A%2F%2Fsonarcloud.io&style=flat-square)](https://sonarcloud.io/dashboard?id=jonas-merkle_serilog-sinks-slackwebhook) |
| Maintenance Status | ![Sonar Code Quality](https://img.shields.io/maintenance/yes/2020?style=flat-square) |

Expand Down Expand Up @@ -53,13 +53,14 @@ Log.Logger = new LoggerConfiguration()
.WriteTo.Slack(
slackWebHookUrl: "https://...",
slackChannel: null
)
.CreateLogger();
```

b) Recommended usage:

```csharp
var logLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: LogEventLevel.Verbos);
var logLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: LogEventLevel.Verbose);
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Slack(
Expand All @@ -73,7 +74,7 @@ Log.Logger = new LoggerConfiguration()
periodicBatchingSinkOptionsQueueLimit: 10000,

sinkRestrictedToMinimumLevel: LogEventLevel.Verbose,
sinkLevelSwitch:logLevelSwitch)
sinkLevelSwitch:logLevelSwitch
)
.CreateLogger();
```
Expand Down Expand Up @@ -114,7 +115,7 @@ Log.Logger = new LoggerConfiguration()
sinkOutputTemplate: null,
sinkLevelSwitch: null,
sinkFormatProvider: null,
statusSwitch: null
sinkActivationSwitch: null
)
.CreateLogger();
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageProjectUrl>https://github.com/jonas-merkle/serilog-sinks-slackwebhook</PackageProjectUrl>
<AssemblyName>Serilog.Sinks.SlackWebHook.Example</AssemblyName>
<RootNamespace>Serilog.Sinks.SlackWebHook.Example</RootNamespace>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Serilog.Sinks.SlackWebHook.Example
{
public static class SlackSinkExample
{
public static void Main(string[] args)
public static void Main()
{
string slackChannel = null;

Expand All @@ -17,9 +17,8 @@ public static void Main(string[] args)

Console.Write("Slack WebHook Url: ");
var input = Console.ReadLine();
string slackWebHookUrl;
if (string.IsNullOrEmpty(input)) throw new ArgumentException("No valid WebHook Url!");
else slackWebHookUrl = input;
var slackWebHookUrl = input;
Console.WriteLine();

Console.Write("Slack Channel (optional): ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<RepositoryUrl>https://github.com/jonas-merkle/serilog-sinks-slackwebhook</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<PackageTags>serilog, serilog-sink, slack, logging, csharp, unit-tests</PackageTags>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public void DefaultConstructorTest()
Assert.IsTrue(options.SlackAttachmentColors.Count == 6);
Assert.IsTrue(options.SlackAttachmentFooterIcon.Count == 6);

Assert.IsTrue(options.SlackPeriodicBatchingSinkOptionsBatchSizeLimit >= 0);
Assert.IsTrue(!options.SlackPeriodicBatchingSinkOptionsPeriod.Equals(TimeSpan.Zero));
Assert.IsTrue(options.SlackPeriodicBatchingSinkOptionsQueueLimit >= 0);
Assert.IsTrue(options.PeriodicBatchingSinkOptionsBatchSizeLimit >= 0);
Assert.IsTrue(!options.PeriodicBatchingSinkOptionsPeriod.Equals(TimeSpan.Zero));
Assert.IsTrue(options.PeriodicBatchingSinkOptionsQueueLimit >= 0);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
<NeutralLanguage></NeutralLanguage>
<SignAssembly>false</SignAssembly>
<PackageId>Serilog.Sinks.SlackWebHook</PackageId>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.1|AnyCPU'">
<WarningLevel>5</WarningLevel>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static class SlackLoggerConfigurationExtensions
/// <param name="sinkOutputTemplate">The template for the output format of the log messages (optional).</param>
/// <param name="sinkLevelSwitch">A <see cref="LoggingLevelSwitch"/> to change the minimum <see cref="LogEventLevel"/> a log message must have to be send to Slack (optional).</param>
/// <param name="sinkFormatProvider">A format provider (optional).</param>
/// <param name="statusSwitch">A Switch to change the activation status of the sink on the fly (optional).</param>
/// <param name="sinkActivationSwitch">A Switch to change the activation status of the sink on the fly (optional).</param>
/// <returns>Instance of <see cref="LoggerConfiguration"/> object.</returns>
public static LoggerConfiguration Slack(
this LoggerSinkConfiguration loggerSinkConfiguration,
Expand Down Expand Up @@ -89,7 +89,7 @@ public static LoggerConfiguration Slack(
string sinkOutputTemplate = null,
LoggingLevelSwitch sinkLevelSwitch = null,
IFormatProvider sinkFormatProvider = null,
SlackSinkActivationSwitch statusSwitch = null
SlackSinkActivationSwitch sinkActivationSwitch = null
)
{
return Slack(loggerSinkConfiguration, slackWebHookUrl, slackUsername, slackEmojiIcon, slackUriIcon,
Expand All @@ -100,7 +100,7 @@ public static LoggerConfiguration Slack(
slackDisplayExtendedInfoAttachmentShort, slackAddExceptionAttachment,
slackDisplayExceptionAttachmentShort, slackConnectionTimeout, slackHttpClientObj, generateSlackFunctions, periodicBatchingSinkOptionsBatchSizeLimit,
periodicBatchingSinkOptionsPeriod, periodicBatchingSinkOptionsQueueLimit, sinkRestrictedToMinimumLevel,
sinkOutputTemplate, sinkLevelSwitch, sinkFormatProvider, statusSwitch);
sinkOutputTemplate, sinkLevelSwitch, sinkFormatProvider, sinkActivationSwitch);
}

/// <summary>
Expand Down Expand Up @@ -137,7 +137,7 @@ public static LoggerConfiguration Slack(
/// <param name="sinkOutputTemplate">The template for the output format of the log messages (optional).</param>
/// <param name="sinkLevelSwitch">A <see cref="LoggingLevelSwitch"/> to change the minimum <see cref="LogEventLevel"/> a log message must have to be send to Slack (optional).</param>
/// <param name="sinkFormatProvider">A format provider (optional).</param>
/// <param name="statusSwitch">A Switch to change the activation status of the sink on the fly (optional).</param>
/// <param name="sinkActivationSwitch">A Switch to change the activation status of the sink on the fly (optional).</param>
/// <returns>Instance of <see cref="LoggerConfiguration"/> object.</returns>
public static LoggerConfiguration Slack(
this LoggerSinkConfiguration loggerSinkConfiguration,
Expand Down Expand Up @@ -180,7 +180,7 @@ public static LoggerConfiguration Slack(
string sinkOutputTemplate = null,
LoggingLevelSwitch sinkLevelSwitch = null,
IFormatProvider sinkFormatProvider = null,
SlackSinkActivationSwitch statusSwitch = null
SlackSinkActivationSwitch sinkActivationSwitch = null
)
{
ParseMode? slackParse = null;
Expand Down Expand Up @@ -220,7 +220,7 @@ public static LoggerConfiguration Slack(
slackDisplayExceptionAttachmentShort, slackConnectionTimeout, slackHttpClient, generateSlackMessageText,
generateSlackMessageAttachments, generateSlackMessageBlocks, periodicBatchingSinkOptionsBatchSizeLimit,
periodicBatchingSinkOptionsPeriod, periodicBatchingSinkOptionsQueueLimit, sinkRestrictedToMinimumLevel,
sinkOutputTemplate, sinkLevelSwitch, sinkFormatProvider, statusSwitch);
sinkOutputTemplate, sinkLevelSwitch, sinkFormatProvider, sinkActivationSwitch);
}

#endregion
Expand Down Expand Up @@ -263,7 +263,7 @@ public static LoggerConfiguration Slack(
/// <param name="sinkOutputTemplate">The template for the output format of the log messages (optional).</param>
/// <param name="sinkLevelSwitch">A <see cref="LoggingLevelSwitch"/> to change the minimum <see cref="LogEventLevel"/> a log message must have to be send to Slack (optional).</param>
/// <param name="sinkFormatProvider">A format provider (optional).</param>
/// <param name="statusSwitch">A Switch to change the activation status of the sink on the fly (optional).</param>
/// <param name="sinkActivationSwitch">A Switch to change the activation status of the sink on the fly (optional).</param>
/// <returns>Instance of <see cref="LoggerConfiguration"/> object.</returns>
private static LoggerConfiguration Slack(
this LoggerSinkConfiguration loggerSinkConfiguration,
Expand Down Expand Up @@ -308,7 +308,7 @@ private static LoggerConfiguration Slack(
string sinkOutputTemplate = null,
LoggingLevelSwitch sinkLevelSwitch = null,
IFormatProvider sinkFormatProvider = null,
SlackSinkActivationSwitch statusSwitch = null
SlackSinkActivationSwitch sinkActivationSwitch = null
)
{
if (slackWebHookUrl == null) throw new ArgumentNullException(nameof(slackWebHookUrl), "The Slack WebHook can't be null!");
Expand Down Expand Up @@ -343,14 +343,14 @@ private static LoggerConfiguration Slack(

if (slackConnectionTimeout != null) slackSinkOptions.SlackConnectionTimeout = (int)slackConnectionTimeout;

if (periodicBatchingSinkOptionsBatchSizeLimit != null) slackSinkOptions.SlackPeriodicBatchingSinkOptionsBatchSizeLimit = (int)periodicBatchingSinkOptionsBatchSizeLimit;
if (periodicBatchingSinkOptionsPeriod != null) slackSinkOptions.SlackPeriodicBatchingSinkOptionsPeriod = (TimeSpan)periodicBatchingSinkOptionsPeriod;
if (periodicBatchingSinkOptionsQueueLimit != null) slackSinkOptions.SlackPeriodicBatchingSinkOptionsQueueLimit = (int)periodicBatchingSinkOptionsQueueLimit;
if (periodicBatchingSinkOptionsBatchSizeLimit != null) slackSinkOptions.PeriodicBatchingSinkOptionsBatchSizeLimit = (int)periodicBatchingSinkOptionsBatchSizeLimit;
if (periodicBatchingSinkOptionsPeriod != null) slackSinkOptions.PeriodicBatchingSinkOptionsPeriod = (TimeSpan)periodicBatchingSinkOptionsPeriod;
if (periodicBatchingSinkOptionsQueueLimit != null) slackSinkOptions.PeriodicBatchingSinkOptionsQueueLimit = (int)periodicBatchingSinkOptionsQueueLimit;

if (sinkOutputTemplate != null) slackSinkOptions.SlackSinkOutputTemplate = sinkOutputTemplate;
if (sinkOutputTemplate != null) slackSinkOptions.SinkOutputTemplate = sinkOutputTemplate;

return loggerSinkConfiguration.Sink(
logEventSink: new SlackSink(slackSinkOptions, sinkFormatProvider, statusSwitch, slackHttpClient,
logEventSink: new SlackSink(slackSinkOptions, sinkFormatProvider, sinkActivationSwitch, slackHttpClient,
generateSlackMessageText, generateSlackMessageAttachments, generateSlackMessageBlocks),
restrictedToMinimumLevel: sinkRestrictedToMinimumLevel ?? LevelAlias.Minimum,
levelSwitch: sinkLevelSwitch);
Expand Down
19 changes: 11 additions & 8 deletions Serilog.Sinks.SlackWebHook/Serilog.Sinks.SlackWebHook/SlackSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SlackSink : PeriodicBatchingSink
/// <summary>
/// <see cref="SlackSinkActivationSwitch"/> to change the activation status of the sink on the fly.
/// </summary>
private readonly SlackSinkActivationSwitch _statusSwitch;
private readonly SlackSinkActivationSwitch _slackSinkActivationSwitch;

/// <summary>
/// <see cref="IFormatProvider"/> object.
Expand Down Expand Up @@ -80,13 +80,13 @@ public SlackSink(
Func<LogEvent, IFormatProvider, object, List<Block>> generateSlackMessageBlocks = null
)
: base(
slackSinkOptions.SlackPeriodicBatchingSinkOptionsBatchSizeLimit,
slackSinkOptions.SlackPeriodicBatchingSinkOptionsPeriod,
slackSinkOptions.SlackPeriodicBatchingSinkOptionsQueueLimit)
slackSinkOptions.PeriodicBatchingSinkOptionsBatchSizeLimit,
slackSinkOptions.PeriodicBatchingSinkOptionsPeriod,
slackSinkOptions.PeriodicBatchingSinkOptionsQueueLimit)
{
_slackSinkOptions = slackSinkOptions;
_formatProvider = formatProvider;
_statusSwitch = statusSwitch ?? new SlackSinkActivationSwitch();
_slackSinkActivationSwitch = statusSwitch ?? new SlackSinkActivationSwitch();
_slackHttpClient = slackHttpClient ?? new HttpClient();

// if no extern generation functions were specified, use the default ones
Expand Down Expand Up @@ -121,9 +121,12 @@ protected override void Dispose(bool disposing)
protected override async Task EmitBatchAsync(IEnumerable<LogEvent> events)
{
// check activation status
if (_statusSwitch.SlackStatus == SlackSinkActivationSwitch.SlackActivationStatus.InActive) return;
if (_slackSinkActivationSwitch.SlackSinkStatus == SlackSinkActivationSwitch.SlackSinkActivationStatus.InActive)
{
return;
}

foreach (var logEvent in events)
foreach (LogEvent logEvent in events)
{
// create new slack message
var msg = new SlackMessage
Expand All @@ -150,7 +153,7 @@ protected override async Task EmitBatchAsync(IEnumerable<LogEvent> events)
// multi channel post
var logMsgPosts = _slackClient.PostToChannelsAsync(msg, _slackSinkOptions.SlackChannels);

foreach (var logMsgPost in logMsgPosts)
foreach (Task<bool> logMsgPost in logMsgPosts)
{
await logMsgPost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class SlackSinkActivationSwitch
/// <summary>
/// Enum to represent an activation status.
/// </summary>
public enum SlackActivationStatus
public enum SlackSinkActivationStatus
{
InActive = 0,
Active = 1
Expand All @@ -23,15 +23,15 @@ public enum SlackActivationStatus
/// <summary>
/// The current status.
/// </summary>
public SlackActivationStatus SlackStatus { get; set; }
public SlackSinkActivationStatus SlackSinkStatus { get; set; }

/// <summary>
/// Initializes new instance of <see cref="SlackSinkActivationSwitch"/>.
/// </summary>
/// <param name="activationStatus">The <see cref="SlackActivationStatus"/>.</param>
public SlackSinkActivationSwitch(SlackActivationStatus activationStatus = SlackActivationStatus.Active)
/// <param name="slackSinkActivationStatus">The <see cref="SlackSinkActivationStatus"/>.</param>
public SlackSinkActivationSwitch(SlackSinkActivationStatus slackSinkActivationStatus = SlackSinkActivationStatus.Active)
{
SlackStatus = activationStatus;
SlackSinkStatus = slackSinkActivationStatus;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static string GenerateSlackMessageText(LogEvent logEvent, IFormatProvider
var slackSinkOptions = (SlackSinkOptions)options ?? throw new InvalidCastException();

// generate the log message text
var textFormatter = new MessageTemplateTextFormatter(slackSinkOptions.SlackSinkOutputTemplate, formatProvider);
var textFormatter = new MessageTemplateTextFormatter(slackSinkOptions.SinkOutputTemplate, formatProvider);
var stringWriter = new StringWriter();
textFormatter.Format(logEvent, stringWriter);

Expand Down
Loading

0 comments on commit 1083ba9

Please sign in to comment.