Add parameter to enable db logging, disabled by default
This commit is contained in:
parent
26da438efe
commit
2c6b61b7e6
5 changed files with 23 additions and 8 deletions
|
@ -5,6 +5,7 @@
|
|||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Geekbot.net.Database
|
|||
{
|
||||
_runParameters = runParameters;
|
||||
_logger = logger;
|
||||
NpgsqlLogManager.Provider = new NpgsqlLoggingProviderAdapter(_logger);
|
||||
NpgsqlLogManager.Provider = new NpgsqlLoggingProviderAdapter(logger, runParameters);
|
||||
}
|
||||
|
||||
public DatabaseContext Initialize()
|
||||
|
@ -46,7 +46,11 @@ namespace Geekbot.net.Database
|
|||
Environment.Exit(GeekbotExitCode.DatabaseConnectionFailed.GetHashCode());
|
||||
}
|
||||
|
||||
if (_runParameters.DbLogging)
|
||||
{
|
||||
_logger.Information(LogSource.Database, $"Connected with {database.Database.ProviderName}");
|
||||
}
|
||||
|
||||
return database;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Lib.Logger;
|
||||
using Npgsql.Logging;
|
||||
using LogLevel = NLog.LogLevel;
|
||||
|
@ -9,17 +10,19 @@ namespace Geekbot.net.Database.LoggingAdapter
|
|||
{
|
||||
private readonly string _name;
|
||||
private readonly IGeekbotLogger _geekbotLogger;
|
||||
private readonly RunParameters _runParameters;
|
||||
|
||||
public NpgsqlLoggingAdapter(string name, IGeekbotLogger geekbotLogger)
|
||||
public NpgsqlLoggingAdapter(string name, IGeekbotLogger geekbotLogger, RunParameters runParameters)
|
||||
{
|
||||
_name = name.Substring(7);
|
||||
_geekbotLogger = geekbotLogger;
|
||||
_runParameters = runParameters;
|
||||
geekbotLogger.Trace(LogSource.Database, $"Loaded Npgsql logging adapter: {name}");
|
||||
}
|
||||
|
||||
public override bool IsEnabled(NpgsqlLogLevel level)
|
||||
{
|
||||
return !_geekbotLogger.LogAsJson() && _geekbotLogger.GetNLogger().IsEnabled(ToGeekbotLogLevel(level));
|
||||
return (_runParameters.DbLogging && _geekbotLogger.GetNLogger().IsEnabled(ToGeekbotLogLevel(level)));
|
||||
}
|
||||
|
||||
public override void Log(NpgsqlLogLevel level, int connectorId, string msg, Exception exception = null)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Geekbot.net.Lib.Logger;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Lib.Logger;
|
||||
using Npgsql.Logging;
|
||||
|
||||
namespace Geekbot.net.Database.LoggingAdapter
|
||||
|
@ -6,15 +7,17 @@ namespace Geekbot.net.Database.LoggingAdapter
|
|||
public class NpgsqlLoggingProviderAdapter : INpgsqlLoggingProvider
|
||||
{
|
||||
private readonly GeekbotLogger _geekbotLogger;
|
||||
private readonly RunParameters _runParameters;
|
||||
|
||||
public NpgsqlLoggingProviderAdapter(GeekbotLogger geekbotLogger)
|
||||
public NpgsqlLoggingProviderAdapter(GeekbotLogger geekbotLogger, RunParameters runParameters)
|
||||
{
|
||||
_geekbotLogger = geekbotLogger;
|
||||
_runParameters = runParameters;
|
||||
}
|
||||
|
||||
public NpgsqlLogger CreateLogger(string name)
|
||||
{
|
||||
return new NpgsqlLoggingAdapter(name, _geekbotLogger);
|
||||
return new NpgsqlLoggingAdapter(name, _geekbotLogger, _runParameters);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,6 +46,10 @@ namespace Geekbot.net.Lib
|
|||
[Option("db-password", Default = "", HelpText = "Set a posgresql password")]
|
||||
public string DbPassword { get; set; }
|
||||
|
||||
// Logging
|
||||
[Option("db-logging", Default = false, HelpText = "Enable database logging")]
|
||||
public bool DbLogging { get; set; }
|
||||
|
||||
/************************************
|
||||
* Redis *
|
||||
************************************/
|
||||
|
|
Loading…
Reference in a new issue