Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-merkle committed Jan 8, 2024
1 parent 6835fce commit 0f605cd
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 611 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace jjm.one.Serilog.Sinks.SlackWebHook.Example;

/// <summary>
/// This class contains examples on how to use the library.
/// This class contains examples on how to use the library.
/// </summary>
public static class SlackSinkExample
{
/// <summary>
/// The main function of the <see cref="SlackSinkExample"/> class.
/// The main function of the <see cref="SlackSinkExample" /> class.
/// </summary>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="Exception"></exception>
Expand Down

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.1.2</Version>
<Version>2.1.3</Version>
<Authors>Jonas Merkle [JJM]</Authors>
<Copyright>© by Jonas Merkle [JJM], 2024.</Copyright>
<Title>jjm.one.Serilog.Sinks.SlackWebHook.Example</Title>
Expand All @@ -15,19 +15,19 @@
<RepositoryUrl>https://github.com/jjm-one/jjm.one.Serilog.Sinks.SlackWebHook</RepositoryUrl>
<IsPackable>false</IsPackable>
<IsTestProject>false</IsTestProject>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>jjm.one.Serilog.Sinks.SlackWebHook.Example.SignKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<LangVersion>latestmajor</LangVersion>
<DocumentationFile>./jjm.one.MiscUtilFunctions.Tests.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<LangVersion>latestmajor</LangVersion>
<DocumentationFile>./jjm.one.MiscUtilFunctions.Tests.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog" Version="3.1.1"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void SetUp()
{
}

public const string ValidWebHook = @"https://slack.com/api/api.test";
private const string ValidWebHook = @"https://slack.com/api/api.test";

[Test]
public void SingleChannel_ConstructorTest_WebHookUrlNull()
Expand All @@ -25,7 +25,7 @@ public void SingleChannel_ConstructorTest_WebHookUrlNull()
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Slack(
null,
null!,
slackChannel: null
)
.CreateLogger();
Expand Down Expand Up @@ -67,7 +67,7 @@ public void MultiChannel_ConstructorTest_WebHookUrlNull()
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Slack(
null,
null!,
slackChannel: null
)
.CreateLogger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void SetUp()
.CreateLogger();
}

public const string ValidWebHook = @"https://slack.com/api/api.test";
private const string ValidWebHook = @"https://slack.com/api/api.test";

[Test]
public void SingleChannel_LoggerTests_LogVerbose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void SetUp()
public void DefaultConstructorTest()
{
var options = new SlackSinkOptions();

Assert.That(options.SlackAttachmentColors.Count == 6);
Assert.That(options.SlackAttachmentFooterIcon.Count == 6);

Expand Down

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.1.2</Version>
<Version>2.1.3</Version>
<Authors>Jonas Merkle [JJM]</Authors>
<Copyright>© by Jonas Merkle [JJM], 2024.</Copyright>
<Title>jjm.one.Serilog.Sinks.SlackWebHook.Tests</Title>
Expand All @@ -15,25 +15,25 @@
<RepositoryUrl>https://github.com/jjm-one/jjm.one.Serilog.Sinks.SlackWebHook</RepositoryUrl>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>jjm.one.Serilog.Sinks.SlackWebHook.Tests.SignKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<LangVersion>latestmajor</LangVersion>
<DocumentationFile>./jjm.one.MiscUtilFunctions.Tests.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<LangVersion>latestmajor</LangVersion>
<DocumentationFile>./jjm.one.MiscUtilFunctions.Tests.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="4.0.1" />
<PackageReference Include="nunit" Version="4.0.1"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="Serilog" Version="3.1.1"/>
<PackageReference Include="Slack.Webhooks" Version="1.1.5"/>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static class SlackLoggerConfigurationExtensions
{
#region private constructors

#pragma warning disable CS1584 // XML comment has syntactically incorrect cref attribute
/// <summary>
/// <see cref="LoggerSinkConfiguration" /> extension that provides configuration chaining.
/// </summary>
Expand Down Expand Up @@ -88,6 +89,7 @@ public static class SlackLoggerConfigurationExtensions
/// <param name="sinkFormatProvider">A format provider (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>
#pragma warning restore CS1584 // XML comment has syntactically incorrect cref attribute
private static LoggerConfiguration Slack(
this LoggerSinkConfiguration loggerSinkConfiguration,

Expand Down Expand Up @@ -155,7 +157,8 @@ private static LoggerConfiguration Slack(
if (slackThreadId is not null) slackSinkOptions.SlackThreadId = slackThreadId;

if (slackAttachmentColors is not null) slackSinkOptions.SlackAttachmentColors = slackAttachmentColors;
if (slackAttachmentFooterIcon is not null) slackSinkOptions.SlackAttachmentFooterIcon = slackAttachmentFooterIcon;
if (slackAttachmentFooterIcon is not null)
slackSinkOptions.SlackAttachmentFooterIcon = slackAttachmentFooterIcon;
if (slackAddShortInfoAttachment is not null)
slackSinkOptions.SlackAddShortInfoAttachment = (bool)slackAddShortInfoAttachment;
if (slackDisplayShortInfoAttachmentShort is not null)
Expand Down Expand Up @@ -191,6 +194,7 @@ private static LoggerConfiguration Slack(

#region public constructors

#pragma warning disable CS1584 // XML comment has syntactically incorrect cref attribute
/// <summary>
/// <see cref="LoggerSinkConfiguration" /> extension that provides configuration chaining.
/// </summary>
Expand Down Expand Up @@ -251,6 +255,7 @@ private static LoggerConfiguration Slack(
/// <param name="sinkFormatProvider">A format provider (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>
#pragma warning restore CS1584 // XML comment has syntactically incorrect cref attribute
public static LoggerConfiguration Slack(
this LoggerSinkConfiguration loggerSinkConfiguration,

Expand Down Expand Up @@ -293,7 +298,7 @@ public static LoggerConfiguration Slack(
)
{
return Slack(loggerSinkConfiguration, slackWebHookUrl, slackUsername, slackEmojiIcon, slackUriIcon,
string.IsNullOrEmpty(slackChannel) ? null : new List<string?> { slackChannel }, slackDeleteOriginal,
string.IsNullOrEmpty(slackChannel) ? null : [slackChannel], slackDeleteOriginal,
slackLinkNames, slackMarkdown, slackParseObj, slackReplaceOriginal,
slackResponseType, slackThreadId, slackAttachmentColorsObj, slackAttachmentFooterIconObj,
slackAddShortInfoAttachment, slackDisplayShortInfoAttachmentShort, slackAddExtendedInfoAttachment,
Expand All @@ -304,6 +309,7 @@ public static LoggerConfiguration Slack(
sinkOutputTemplate, sinkLevelSwitch, sinkFormatProvider, sinkActivationSwitch);
}

#pragma warning disable CS1584 // XML comment has syntactically incorrect cref attribute
/// <summary>
/// <see cref="LoggerSinkConfiguration" /> extension that provides configuration chaining.
/// </summary>
Expand Down Expand Up @@ -367,6 +373,7 @@ public static LoggerConfiguration Slack(
/// <param name="sinkFormatProvider">A format provider (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>
#pragma warning restore CS1584 // XML comment has syntactically incorrect cref attribute
public static LoggerConfiguration Slack(
this LoggerSinkConfiguration loggerSinkConfiguration,

Expand Down Expand Up @@ -428,15 +435,12 @@ public static LoggerConfiguration Slack(

if (generateSlackFunctions is not null)
{
if (generateSlackFunctions.Item1 is not null)
generateSlackMessageText =
(Func<LogEvent, IFormatProvider?, object, string?>)generateSlackFunctions.Item1;
if (generateSlackFunctions.Item2 is not null)
generateSlackMessageAttachments =
(Func<LogEvent, IFormatProvider?, object, List<SlackAttachment>?>)generateSlackFunctions.Item2;
if (generateSlackFunctions.Item3 is not null)
generateSlackMessageBlocks =
(Func<LogEvent, IFormatProvider?, object, List<Block>?>)generateSlackFunctions.Item3;
generateSlackMessageText =
(Func<LogEvent, IFormatProvider?, object, string?>)generateSlackFunctions.Item1;
generateSlackMessageAttachments =
(Func<LogEvent, IFormatProvider?, object, List<SlackAttachment>?>)generateSlackFunctions.Item2;
generateSlackMessageBlocks =
(Func<LogEvent, IFormatProvider?, object, List<Block>?>)generateSlackFunctions.Item3;
}

return Slack(loggerSinkConfiguration, slackWebHookUrl, slackUsername, slackEmojiIcon, slackUriIcon,
Expand Down
35 changes: 18 additions & 17 deletions src/jjm.one.Serilog.Sinks.SlackWebHook/SlackSinkMessageTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,22 @@ public static string GenerateSlackMessageText(LogEvent logEvent, IFormatProvider
Color = slackSinkOptions.SlackAttachmentColors[logEvent.Level],
Fallback =
$"{logEvent.Timestamp.ToString(formatProvider)} [{logEvent.Level}] - {logEvent.RenderMessage()}",
Fields = new List<SlackField>
{
new()
Fields =
[
new SlackField
{
Short = slackSinkOptions.SlackDisplayShortInfoAttachmentShort,
Title = "Level",
Value = logEvent.Level.ToString()
},
new()

new SlackField
{
Short = slackSinkOptions.SlackDisplayShortInfoAttachmentShort,
Title = "Timestamp",
Value = logEvent.Timestamp.ToString(formatProvider)
}
},
],
Footer = null,
FooterIcon = slackSinkOptions.SlackAttachmentFooterIcon[logEvent.Level],
ImageUrl = null,
Expand Down Expand Up @@ -160,40 +161,40 @@ public static string GenerateSlackMessageText(LogEvent logEvent, IFormatProvider
Color = slackSinkOptions.SlackAttachmentColors[logEvent.Level],
Fallback =
$"{logEvent.Timestamp.ToString(formatProvider)} Exception: {logEvent.Exception.Message} \n {logEvent.Exception.StackTrace}",
Fields = new List<SlackField>
{
new()
Fields =
[
new SlackField
{
Short = slackSinkOptions.SlackDisplayExceptionAttachmentShort,
Title = "Message",
Value = logEvent.Exception.Message
},
new()

new SlackField
{
Short = slackSinkOptions.SlackDisplayExceptionAttachmentShort,
Title = "Type",
Value = $"`{logEvent.Exception.GetType().Name}`"
},
new()

new SlackField
{
Short = false,
Title = "Stack Trace",
Value = $"```{logEvent.Exception.StackTrace}```"
},
new()

new SlackField
{
Short = false,
Title = "Exception",
Value = $"```{logEvent.Exception}```"
}
},
],
Footer = null,
FooterIcon = slackSinkOptions.SlackAttachmentFooterIcon[logEvent.Level],
ImageUrl = null,
MarkdownIn = new List<string>
{
"fields"
},
MarkdownIn = ["fields"],
Pretext = null,
Text = null,
ThumbUrl = null,
Expand All @@ -207,7 +208,7 @@ public static string GenerateSlackMessageText(LogEvent logEvent, IFormatProvider

#endregion

return attachments.Any() ? attachments : null;
return attachments.Any() ? attachments : null;
}

/// <summary>
Expand Down
14 changes: 8 additions & 6 deletions src/jjm.one.Serilog.Sinks.SlackWebHook/SlackSinkOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Serilog.Events;
using Slack.Webhooks;

// ReSharper disable RedundantDefaultMemberInitializer

namespace jjm.one.Serilog.Sinks.SlackWebHook;

/// <summary>
Expand All @@ -22,32 +24,32 @@ public class SlackSinkOptions

#endregion

#region default values
#region private default values

/// <summary>
/// Default value for the OutputTemplate.
/// </summary>
public const string DefaultOutputTemplate = "{Message:lj}";
private const string DefaultOutputTemplate = "{Message:lj}";

/// <summary>
/// Default value for the BatchSizeLimit.
/// </summary>
public const int DefaultBatchSizeLimit = 10;
private const int DefaultBatchSizeLimit = 10;

/// <summary>
/// Default value for the Period.
/// </summary>
public static readonly TimeSpan DefaultPeriod = TimeSpan.FromSeconds(2);
private static readonly TimeSpan DefaultPeriod = TimeSpan.FromSeconds(2);

/// <summary>
/// Default value for the QueueLimit.
/// </summary>
public const int DefaultQueueLimit = 10000;
private const int DefaultQueueLimit = 10000;

/// <summary>
/// Default value for the Timeout.
/// </summary>
public const int DefaultTimeout = 1000;
private const int DefaultTimeout = 1000;

#endregion

Expand Down
Loading

0 comments on commit 0f605cd

Please sign in to comment.