Browse Source

switch to serilog config

pull/2/head
Kyle Spearrin 4 years ago
parent
commit
c0f0967fa6
  1. 2
      src/CryptoAgent/CryptoAgent.csproj
  2. 1
      src/CryptoAgent/CryptoAgentSettings.cs
  3. 21
      src/CryptoAgent/Program.cs
  4. 5
      src/CryptoAgent/Startup.cs
  5. 17
      src/CryptoAgent/appsettings.Development.json
  6. 25
      src/CryptoAgent/appsettings.json

2
src/CryptoAgent/CryptoAgent.csproj

@ -17,6 +17,8 @@ @@ -17,6 +17,8 @@
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="JsonFlatFileDataStore" Version="2.2.3" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.2.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="VaultSharp" Version="1.7.0" />
</ItemGroup>

1
src/CryptoAgent/CryptoAgentSettings.cs

@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
{
public class CryptoAgentSettings
{
public string LogFilePath { get; set; }
public string IdentityServerUri { get; set; }
public DatabaseSettings Database { get; set; }

21
src/CryptoAgent/Program.cs

@ -11,32 +11,13 @@ namespace Bit.CryptoAgent @@ -11,32 +11,13 @@ namespace Bit.CryptoAgent
{
Host
.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureLogging((hostingContext, logging) =>
{
var settings = new CryptoAgentSettings();
ConfigurationBinder.Bind(
hostingContext.Configuration.GetSection("CryptoAgentSettings"), settings);
var serilogConfig = new LoggerConfiguration()
.Enrich.FromLogContext();
if (!string.IsNullOrWhiteSpace(settings.LogFilePath))
{
serilogConfig.WriteTo.File(settings.LogFilePath, rollOnFileSizeLimit: true,
rollingInterval: RollingInterval.Day);
}
var serilog = serilogConfig.CreateLogger();
logging.AddSerilog(serilog);
});
})
.Build()
.Run();
}
}
}

5
src/CryptoAgent/Startup.cs

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Identity; @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using System;
using System.Globalization;
using System.Security.Claims;
@ -22,6 +23,10 @@ namespace Bit.CryptoAgent @@ -22,6 +23,10 @@ namespace Bit.CryptoAgent
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
Configuration = configuration;
Environment = env;
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
}
public IConfiguration Configuration { get; }

17
src/CryptoAgent/appsettings.Development.json

@ -1,11 +1,16 @@ @@ -1,11 +1,16 @@
{
"Logging": {
"LogLevel": {
"Default": "Information"
}
"Serilog": {
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "Console"
}
],
"Enrich": [
"FromLogContext"
]
},
"cryptoAgentSettings": {
"identityServerUri": "http://localhost:33656/",
"logFilePath": null
"identityServerUri": "http://localhost:33656/"
}
}

25
src/CryptoAgent/appsettings.json

@ -1,14 +1,29 @@ @@ -1,14 +1,29 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Serilog": {
"MinimumLevel": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "File",
"Args": {
"path": "/etc/bitwarden/logs/log.txt",
"rollOnFileSizeLimit": true,
"rollingInterval": "Day"
}
}
],
"Enrich": [
"FromLogContext"
]
},
"AllowedHosts": "*",
"cryptoAgentSettings": {
"logFilePath": "/etc/bitwarden/logs/log.txt",
"identityServerUri": "https://identity.bitwarden.com/",
"database": {
"provider": "json",

Loading…
Cancel
Save