-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+semver: minor | added logging service as a configuration that will b…
…e enabled/disabled via env variable (#91) * +semver: minor | added logging service as a configuration that will be enabled/disabled via env variable * removed entry for appsettings.json in csproj file * +semver: chore | updated readme and removed Microsoft.Extensions.Configuration.Json Nuget package --------- Co-authored-by: Mohammed Owes <[email protected]>
- Loading branch information
Showing
7 changed files
with
83 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
namespace directory_deleter; | ||
using directory_deleter.Services; | ||
using Serilog; | ||
|
||
namespace directory_deleter; | ||
|
||
public partial class App : Application | ||
{ | ||
public App() | ||
{ | ||
InitializeComponent(); | ||
private readonly ISettingsService _service; | ||
public App(IServiceProvider provider) | ||
{ | ||
InitializeComponent(); | ||
MainPage = new AppShell(); | ||
|
||
MainPage = new AppShell(); | ||
} | ||
_service = provider.GetService<ISettingsService>(); | ||
RegisterLogger(); | ||
} | ||
private void RegisterLogger() | ||
{ | ||
if (_service.EnableLogs) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.WriteTo.File(Path.Combine(FileSystem.AppDataDirectory, "directory-delete.log"), | ||
rollingInterval: RollingInterval.Day) | ||
.CreateLogger(); | ||
} | ||
} | ||
} |
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,30 +1,37 @@ | ||
using CommunityToolkit.Maui; | ||
using Serilog; | ||
using directory_deleter.Services; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace directory_deleter; | ||
|
||
public static class MauiProgram | ||
{ | ||
public static MauiApp CreateMauiApp() | ||
{ | ||
#if DEBUG | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.WriteTo.File(Path.Combine(FileSystem.AppDataDirectory, "directory-delete.log"), rollingInterval: RollingInterval.Day) | ||
.CreateLogger(); | ||
Console.WriteLine($"App Installed Location is {FileSystem.AppDataDirectory}"); | ||
#endif | ||
|
||
var builder = MauiApp.CreateBuilder(); | ||
builder | ||
.UseMauiApp<App>() | ||
.UseMauiCommunityToolkit() | ||
.RegisterServices() | ||
.ConfigureFonts(fonts => | ||
{ | ||
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); | ||
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); | ||
}); | ||
|
||
IConfiguration config = new ConfigurationBuilder() | ||
.AddEnvironmentVariables() | ||
.Build(); | ||
|
||
builder.Configuration.AddConfiguration(config); | ||
|
||
return builder.Build(); | ||
} | ||
|
||
public static MauiAppBuilder RegisterServices(this MauiAppBuilder mauiAppBuilder) | ||
{ | ||
mauiAppBuilder.Services.AddScoped<ISettingsService, SettingsService>(); | ||
|
||
return mauiAppBuilder; | ||
} | ||
} |
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,7 @@ | ||
namespace directory_deleter.Services | ||
{ | ||
public interface ISettingsService | ||
{ | ||
bool EnableLogs { get; set; } | ||
} | ||
} |
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,14 @@ | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace directory_deleter.Services | ||
{ | ||
public class SettingsService : ISettingsService | ||
{ | ||
public bool EnableLogs { get; set; } | ||
|
||
public SettingsService() | ||
{ | ||
EnableLogs = Environment.GetEnvironmentVariable("DD_EnableLogs") == "1"; | ||
} | ||
} | ||
} |
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