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_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_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_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_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_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@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;
|
_runParameters = runParameters;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
NpgsqlLogManager.Provider = new NpgsqlLoggingProviderAdapter(_logger);
|
NpgsqlLogManager.Provider = new NpgsqlLoggingProviderAdapter(logger, runParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatabaseContext Initialize()
|
public DatabaseContext Initialize()
|
||||||
|
@ -45,8 +45,12 @@ namespace Geekbot.net.Database
|
||||||
_logger.Error(LogSource.Geekbot, "Could not Connect to datbase", e);
|
_logger.Error(LogSource.Geekbot, "Could not Connect to datbase", e);
|
||||||
Environment.Exit(GeekbotExitCode.DatabaseConnectionFailed.GetHashCode());
|
Environment.Exit(GeekbotExitCode.DatabaseConnectionFailed.GetHashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Information(LogSource.Database, $"Connected with {database.Database.ProviderName}");
|
if (_runParameters.DbLogging)
|
||||||
|
{
|
||||||
|
_logger.Information(LogSource.Database, $"Connected with {database.Database.ProviderName}");
|
||||||
|
}
|
||||||
|
|
||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.Logger;
|
using Geekbot.net.Lib.Logger;
|
||||||
using Npgsql.Logging;
|
using Npgsql.Logging;
|
||||||
using LogLevel = NLog.LogLevel;
|
using LogLevel = NLog.LogLevel;
|
||||||
|
@ -9,17 +10,19 @@ namespace Geekbot.net.Database.LoggingAdapter
|
||||||
{
|
{
|
||||||
private readonly string _name;
|
private readonly string _name;
|
||||||
private readonly IGeekbotLogger _geekbotLogger;
|
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);
|
_name = name.Substring(7);
|
||||||
_geekbotLogger = geekbotLogger;
|
_geekbotLogger = geekbotLogger;
|
||||||
|
_runParameters = runParameters;
|
||||||
geekbotLogger.Trace(LogSource.Database, $"Loaded Npgsql logging adapter: {name}");
|
geekbotLogger.Trace(LogSource.Database, $"Loaded Npgsql logging adapter: {name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsEnabled(NpgsqlLogLevel level)
|
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)
|
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;
|
using Npgsql.Logging;
|
||||||
|
|
||||||
namespace Geekbot.net.Database.LoggingAdapter
|
namespace Geekbot.net.Database.LoggingAdapter
|
||||||
|
@ -6,15 +7,17 @@ namespace Geekbot.net.Database.LoggingAdapter
|
||||||
public class NpgsqlLoggingProviderAdapter : INpgsqlLoggingProvider
|
public class NpgsqlLoggingProviderAdapter : INpgsqlLoggingProvider
|
||||||
{
|
{
|
||||||
private readonly GeekbotLogger _geekbotLogger;
|
private readonly GeekbotLogger _geekbotLogger;
|
||||||
|
private readonly RunParameters _runParameters;
|
||||||
|
|
||||||
public NpgsqlLoggingProviderAdapter(GeekbotLogger geekbotLogger)
|
public NpgsqlLoggingProviderAdapter(GeekbotLogger geekbotLogger, RunParameters runParameters)
|
||||||
{
|
{
|
||||||
_geekbotLogger = geekbotLogger;
|
_geekbotLogger = geekbotLogger;
|
||||||
|
_runParameters = runParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NpgsqlLogger CreateLogger(string name)
|
public NpgsqlLogger CreateLogger(string name)
|
||||||
{
|
{
|
||||||
return new NpgsqlLoggingAdapter(name, _geekbotLogger);
|
return new NpgsqlLoggingAdapter(name, _geekbotLogger, _runParameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -45,6 +45,10 @@ namespace Geekbot.net.Lib
|
||||||
|
|
||||||
[Option("db-password", Default = "", HelpText = "Set a posgresql password")]
|
[Option("db-password", Default = "", HelpText = "Set a posgresql password")]
|
||||||
public string DbPassword { get; set; }
|
public string DbPassword { get; set; }
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
[Option("db-logging", Default = false, HelpText = "Enable database logging")]
|
||||||
|
public bool DbLogging { get; set; }
|
||||||
|
|
||||||
/************************************
|
/************************************
|
||||||
* Redis *
|
* Redis *
|
||||||
|
|
Loading…
Reference in a new issue