-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Default Configuration Builder (#118)
* Refactored to an Proxy interface to address #47 * Added remaining EventsSent to ConfigurationManager * Attempting to eliminate memory leak * Adding script to test the Plugin template * WIP * Updated to be more cross-platform friendly * Re-added cheer graffiti * Cleaning up the inner-loop build-debug-process * Addressed logger and memory leak issues #73 #114 * Added a default configuration builder #34 Addressed logger and memory leak issues #73 #114 (#117) * Refactored to an Proxy interface to address #47 * Added remaining EventsSent to ConfigurationManager * Attempting to eliminate memory leak * Adding script to test the Plugin template * WIP * Updated to be more cross-platform friendly * Re-added cheer graffiti * Cleaning up the inner-loop build-debug-process * Addressed logger and memory leak issues #73 #114
- Loading branch information
1 parent
ee798c2
commit 827ce2b
Showing
5 changed files
with
111 additions
and
76 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
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
using Serilog; | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using CONFIG = Microsoft.Extensions.Configuration; | ||
|
||
namespace StreamDeckLib.Config | ||
{ | ||
public class ConfigurationBuilder : IDisposable | ||
{ | ||
|
||
private ConfigurationBuilder(string[] args) { | ||
|
||
#if DEBUG | ||
// This gives us our "first chance" debugging, before even parsing the command | ||
// line args, without the need to manually edit the code to toggle the feature | ||
// ability on or off. | ||
|
||
if (args.Select(arg => arg.Replace("--", "-")) | ||
.Any(arg => arg.Equals("-break"))) | ||
{ | ||
Console.WriteLine("Debugging has been requested. Waiting for a debugger to attach..."); | ||
Debugger.Launch(); | ||
|
||
while (!Debugger.IsAttached) | ||
{ | ||
Task.Delay(500).GetAwaiter().GetResult(); | ||
Console.Write("."); | ||
} | ||
} | ||
#endif | ||
} | ||
private static ConfigurationBuilder Instance; | ||
|
||
public static ConfigurationBuilder BuildDefaultConfiguration(string[] args) { | ||
|
||
var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
Directory.SetCurrentDirectory(dir); | ||
|
||
var configuration = new CONFIG.ConfigurationBuilder() | ||
.AddJsonFile("appsettings.json") | ||
.Build(); | ||
|
||
Log.Logger = new LoggerConfiguration() | ||
.ReadFrom.Configuration(configuration) | ||
.CreateLogger(); | ||
|
||
Instance = new ConfigurationBuilder(args) | ||
{ | ||
LoggerFactory = new LoggerFactory() | ||
.AddSerilog(Log.Logger) | ||
}; | ||
|
||
return Instance; | ||
|
||
} | ||
|
||
public ILoggerFactory LoggerFactory { get; private set; } | ||
|
||
|
||
public void Dispose() | ||
{ | ||
|
||
#if DEBUG | ||
if (Debugger.IsAttached) | ||
{ | ||
// If a debugger is attached, give the developer a last chance to inspect | ||
// variables, state, etc. before the process terminates. | ||
Debugger.Break(); | ||
} | ||
#endif | ||
|
||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" /> | ||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> | ||
<PackageReference Include="Serilog" Version="2.7.1" /> | ||
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" /> | ||
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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