Skip to content

Commit

Permalink
Added Example app
Browse files Browse the repository at this point in the history
  • Loading branch information
chancity committed Dec 4, 2018
1 parent 8afd26f commit c384a14
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 7 deletions.
6 changes: 6 additions & 0 deletions discord-web-hook-logger.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.27428.2037
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "discord-web-hook-logger", "src\discord-web-hook-logger.csproj", "{DDA367C2-F532-4148-91D2-3E03BCE5DDCA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example", "example\example.csproj", "{6FA534A1-5134-438A-83D6-BD9FC2460F7D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{DDA367C2-F532-4148-91D2-3E03BCE5DDCA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDA367C2-F532-4148-91D2-3E03BCE5DDCA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDA367C2-F532-4148-91D2-3E03BCE5DDCA}.Release|Any CPU.Build.0 = Release|Any CPU
{6FA534A1-5134-438A-83D6-BD9FC2460F7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6FA534A1-5134-438A-83D6-BD9FC2460F7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FA534A1-5134-438A-83D6-BD9FC2460F7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FA534A1-5134-438A-83D6-BD9FC2460F7D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 6 additions & 0 deletions example/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
</configuration>
33 changes: 33 additions & 0 deletions example/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using discord_web_hook_logger;
using Microsoft.Extensions.Logging;

namespace example
{
class Program
{
//Webhook URL https://discordapp.com/api/webhooks/519560492172181519/p9feyLifxedaxy50b8lAmnG3GZZ3lkAjKpJhuJO_gZSeR-9ZwAoStzgqztJ5wU1-cge6
//Id 519560492172181519
//Token p9feyLifxedaxy50b8lAmnG3GZZ3lkAjKpJhuJO_gZSeR-9ZwAoStzgqztJ5wU1-cge6
static void Main(string[] args)
{
var discordChannelId = 519560492172181519;
var discordChannelToken = "p9feyLifxedaxy50b8lAmnG3GZZ3lkAjKpJhuJO_gZSeR-9ZwAoStzgqztJ5wU1-cge6";

var logger = DicordLogFactory.GetLogger<Program>(discordChannelId, discordChannelToken);

logger.LogCritical("Test Critical Log");
logger.LogError("Test Error Log");
logger.LogDebug("Test Debug Log");
logger.LogWarning("Test Warning Log");
logger.LogInformation("Test Information Log");
logger.LogTrace("Test Trace Log");

Console.ReadLine();
}
}
}
36 changes: 36 additions & 0 deletions example/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("example")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("example")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6fa534a1-5134-438a-83d6-bd9fc2460f7d")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
63 changes: 63 additions & 0 deletions example/example.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6FA534A1-5134-438A-83D6-BD9FC2460F7D}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>example</RootNamespace>
<AssemblyName>example</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\discord-web-hook-logger.csproj">
<Project>{dda367c2-f532-4148-91d2-3e03bce5ddca}</Project>
<Name>discord-web-hook-logger</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
4 changes: 4 additions & 0 deletions example/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Extensions.Logging.Abstractions" version="2.1.1" targetFramework="net462" />
</packages>
9 changes: 4 additions & 5 deletions src/DiscordLogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ private static bool Filter(string arg1, LogLevel arg2)
}


public static ILogger<T> GetLogger<T>(ulong id, string token, Dictionary<string, Color> colorMap = null)
public static ILogger<T> GetLogger<T>(long channelId, string channelToken, Dictionary<string, Color> colorMap = null)
{
return new DiscordLogger<T>(LoggerFactory, id, token, colorMap);
return new DiscordLogger<T>(LoggerFactory, channelId, channelToken, colorMap);
}
}

Expand All @@ -61,7 +61,7 @@ public class DiscordLogger<T> : ILogger<T>
private readonly string _type;
private readonly WebHookClient _webHookClient;

public DiscordLogger(ILoggerFactory factory, ulong id, string token, Dictionary<string, Color> colorMap)
public DiscordLogger(ILoggerFactory factory, long channelId, string channelToken, Dictionary<string, Color> colorMap)
{
if (factory == null)
{
Expand All @@ -79,7 +79,7 @@ public DiscordLogger(ILoggerFactory factory, ulong id, string token, Dictionary<
}


_webHookClient = new WebHookClient(id, token, colorMap)
_webHookClient = new WebHookClient(channelId, channelToken, colorMap)
{
MergeAllTypes = false
};
Expand All @@ -99,7 +99,6 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
if (logLevel == LogLevel.Critical)
{
_webHookClient.ForceSendLogMessage(logLevel.ToString(), description, exception?.StackTrace);
Environment.Exit(0);
}

if (logLevel >= LogLevel.Error)
Expand Down
4 changes: 2 additions & 2 deletions src/WebHookClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public partial class WebHookClient
{
private readonly Dictionary<string, int> _colorMap;

public WebHookClient(ulong id, string token, Dictionary<string, Color> colorMap = null) : this(
$"https://discordapp.com/api/webhooks/{id}/{token}", colorMap) { }
public WebHookClient(long channelId, string channelToken, Dictionary<string, Color> colorMap = null) : this(
$"https://discordapp.com/api/webhooks/{channelId}/{channelToken}", colorMap) { }

public WebHookClient(string webhookUrl, Dictionary<string, Color> colorMap = null)
{
Expand Down

0 comments on commit c384a14

Please sign in to comment.