-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from jjm-one/develop
Develop
- Loading branch information
Showing
17 changed files
with
1,990 additions
and
1,805 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
169 changes: 89 additions & 80 deletions
169
src/jjm.one.Serilog.Sinks.SlackWebHook.Example/SlackSinkExample.cs
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 |
---|---|---|
@@ -1,88 +1,97 @@ | ||
using Serilog; | ||
using System; | ||
using System.Threading; | ||
using Serilog; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
using System; | ||
|
||
namespace jjm.one.Serilog.Sinks.SlackWebHook.Example | ||
namespace jjm.one.Serilog.Sinks.SlackWebHook.Example; | ||
|
||
/// <summary> | ||
/// This class contains examples on how to use the library. | ||
/// </summary> | ||
public static class SlackSinkExample | ||
{ | ||
public static class SlackSinkExample | ||
/// <summary> | ||
/// The main function of the <see cref="SlackSinkExample"/> class. | ||
/// </summary> | ||
/// <exception cref="ArgumentException"></exception> | ||
/// <exception cref="Exception"></exception> | ||
public static void Main() | ||
{ | ||
public static void Main() | ||
string? slackChannel = null; | ||
|
||
Console.WriteLine( | ||
"####################################################################################################"); | ||
Console.WriteLine("Serilog Slack Sink Example (ver. " + typeof(SlackSinkExample).Assembly.GetName().Version + | ||
")"); | ||
Console.WriteLine( | ||
"####################################################################################################"); | ||
Console.WriteLine(); | ||
|
||
Console.Write("Slack WebHook Url: "); | ||
var input = Console.ReadLine(); | ||
if (string.IsNullOrEmpty(input)) throw new ArgumentException("No valid WebHook Url!"); | ||
var slackWebHookUrl = input; | ||
Console.WriteLine(); | ||
|
||
Console.Write("Slack Channel (optional): "); | ||
input = Console.ReadLine(); | ||
if (!string.IsNullOrEmpty(input)) slackChannel = input; | ||
Console.WriteLine(); | ||
|
||
Console.Write("Slack Username (optional): "); | ||
input = Console.ReadLine(); | ||
var slackUsername = string.IsNullOrEmpty(input) ? input : "Serilog Slack Sink Example"; | ||
Console.WriteLine(); | ||
|
||
Console.Write("Slack User Icon (optional): "); | ||
input = Console.ReadLine(); | ||
var slackUserIcon = string.IsNullOrEmpty(input) ? input : ":monkey_face:"; | ||
Console.WriteLine(); | ||
|
||
var levelSwitch = new LoggingLevelSwitch(LogEventLevel.Verbose); | ||
|
||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Verbose() | ||
.WriteTo.Slack( | ||
slackWebHookUrl, | ||
slackChannel, | ||
slackUsername, | ||
slackUserIcon, | ||
periodicBatchingSinkOptionsBatchSizeLimit: 1, | ||
periodicBatchingSinkOptionsPeriod: TimeSpan.FromMilliseconds(10), | ||
periodicBatchingSinkOptionsQueueLimit: 100, | ||
sinkRestrictedToMinimumLevel: LogEventLevel.Verbose, | ||
sinkOutputTemplate: "{Message}", | ||
sinkLevelSwitch: levelSwitch | ||
) | ||
.CreateLogger(); | ||
|
||
Log.Write(LogEventLevel.Verbose, "Verbose Logging Message"); | ||
Log.Write(LogEventLevel.Debug, "Debug Logging Message"); | ||
Log.Write(LogEventLevel.Information, "Information Logging Message"); | ||
Log.Write(LogEventLevel.Warning, "Warning Logging Message"); | ||
Log.Write(LogEventLevel.Error, "Error Logging Message"); | ||
Log.Write(LogEventLevel.Fatal, "Fatal Logging Message"); | ||
|
||
try | ||
{ | ||
throw new Exception("TEST EXCEPTION!"); | ||
} | ||
catch (Exception e) | ||
{ | ||
string slackChannel = null; | ||
|
||
Console.WriteLine("####################################################################################################"); | ||
Console.WriteLine("Serilog Slack Sink Example (ver. " + typeof(SlackSinkExample).Assembly.GetName().Version + ")"); | ||
Console.WriteLine("####################################################################################################"); | ||
Console.WriteLine(); | ||
|
||
Console.Write("Slack WebHook Url: "); | ||
var input = Console.ReadLine(); | ||
if (string.IsNullOrEmpty(input)) throw new ArgumentException("No valid WebHook Url!"); | ||
var slackWebHookUrl = input; | ||
Console.WriteLine(); | ||
|
||
Console.Write("Slack Channel (optional): "); | ||
input = Console.ReadLine(); | ||
if (!string.IsNullOrEmpty(input)) slackChannel = input; | ||
Console.WriteLine(); | ||
|
||
Console.Write("Slack Username (optional): "); | ||
input = Console.ReadLine(); | ||
var slackUsername = string.IsNullOrEmpty(input) ? input : "Serilog Slack Sink Example"; | ||
Console.WriteLine(); | ||
|
||
Console.Write("Slack User Icon (optional): "); | ||
input = Console.ReadLine(); | ||
var slackUserIcon = string.IsNullOrEmpty(input) ? input : ":monkey_face:"; | ||
Console.WriteLine(); | ||
|
||
var levelSwitch = new LoggingLevelSwitch(initialMinimumLevel: LogEventLevel.Verbose); | ||
|
||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Verbose() | ||
.WriteTo.Slack( | ||
slackWebHookUrl: slackWebHookUrl, | ||
slackChannel: slackChannel, | ||
slackUsername: slackUsername, | ||
slackEmojiIcon: slackUserIcon, | ||
|
||
periodicBatchingSinkOptionsBatchSizeLimit: 1, | ||
periodicBatchingSinkOptionsPeriod: TimeSpan.FromMilliseconds(10), | ||
periodicBatchingSinkOptionsQueueLimit: 100, | ||
|
||
sinkRestrictedToMinimumLevel: LogEventLevel.Verbose, | ||
sinkOutputTemplate: "{Message}", | ||
sinkLevelSwitch: levelSwitch | ||
) | ||
.CreateLogger(); | ||
|
||
Log.Write(LogEventLevel.Verbose, "Verbose Logging Message"); | ||
Log.Write(LogEventLevel.Debug, "Debug Logging Message"); | ||
Log.Write(LogEventLevel.Information, "Information Logging Message"); | ||
Log.Write(LogEventLevel.Warning, "Warning Logging Message"); | ||
Log.Write(LogEventLevel.Error, "Error Logging Message"); | ||
Log.Write(LogEventLevel.Fatal, "Fatal Logging Message"); | ||
|
||
try | ||
{ | ||
throw new Exception("TEST EXCEPTION!"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.Write(LogEventLevel.Fatal, e, "Fatal Logging Message with exception"); | ||
} | ||
|
||
levelSwitch.MinimumLevel = LogEventLevel.Fatal; | ||
|
||
Log.Write(LogEventLevel.Error, "This Message shouldn't be send to Slack!"); | ||
|
||
System.Threading.Thread.Sleep(10000); | ||
|
||
Console.WriteLine("Press any key to finish..."); | ||
Console.ReadKey(); | ||
|
||
Environment.Exit(0); | ||
Log.Write(LogEventLevel.Fatal, e, "Fatal Logging Message with exception"); | ||
} | ||
|
||
levelSwitch.MinimumLevel = LogEventLevel.Fatal; | ||
|
||
Log.Write(LogEventLevel.Error, "This Message shouldn't be send to Slack!"); | ||
|
||
Thread.Sleep(10000); | ||
|
||
Console.WriteLine("Press any key to finish..."); | ||
Console.ReadKey(); | ||
|
||
Environment.Exit(0); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/jjm.one.Serilog.Sinks.SlackWebHook.Example/jjm.one.MiscUtilFunctions.Tests.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
61 changes: 30 additions & 31 deletions
61
....one.Serilog.Sinks.SlackWebHook.Example/jjm.one.Serilog.Sinks.SlackWebHook.Example.csproj
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 |
---|---|---|
@@ -1,38 +1,37 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Version>2.0.2</Version> | ||
<Authors>Jonas Merkle [JJM] </Authors> | ||
<Copyright>© by Jonas Merkle [JJM], 2023.</Copyright> | ||
<RootNamespace>jm.one.Serilog.Sinks.SlackWebHook.Example</RootNamespace> | ||
<Title>jm.one.Serilog.Sinks.SlackWebHook.Example</Title> | ||
<Description>A basic Slack Sink for the Serilog framwork. (Example)</Description> | ||
<PackageTags>serilog, serilog-sink, slack, logging, csharp, example</PackageTags> | ||
<PackageProjectUrl>https://github.com/jjm-one/jjm.one.Serilog.Sinks.SlackWebHook</PackageProjectUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<RepositoryUrl>https://github.com/jjm-one/jjm.one.Serilog.Sinks.SlackWebHook</RepositoryUrl> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>false</IsTestProject> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Version>2.1.0</Version> | ||
<Authors>Jonas Merkle [JJM]</Authors> | ||
<Copyright>© by Jonas Merkle [JJM], 2023.</Copyright> | ||
<Title>jjm.one.Serilog.Sinks.SlackWebHook.Example</Title> | ||
<Description>A basic Slack Sink for the Serilog framwork. (Example)</Description> | ||
<PackageTags>serilog, serilog-sink, slack, logging, csharp, example</PackageTags> | ||
<PackageProjectUrl>https://github.com/jjm-one/jjm.one.Serilog.Sinks.SlackWebHook</PackageProjectUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<RepositoryUrl>https://github.com/jjm-one/jjm.one.Serilog.Sinks.SlackWebHook</RepositoryUrl> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>false</IsTestProject> | ||
</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> | ||
<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.0.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Serilog" Version="3.0.1"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\jjm.one.Serilog.Sinks.SlackWebHook\jjm.one.Serilog.Sinks.SlackWebHook.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\jjm.one.Serilog.Sinks.SlackWebHook\jjm.one.Serilog.Sinks.SlackWebHook.csproj"/> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.