|
|
@ -33,23 +33,26 @@ namespace NzbDrone.Core.Instrumentation
|
|
|
|
|
|
|
|
|
|
|
|
LogManager.Configuration.AddTarget("DbLogger", target);
|
|
|
|
LogManager.Configuration.AddTarget("DbLogger", target);
|
|
|
|
LogManager.Configuration.LoggingRules.Add(Rule);
|
|
|
|
LogManager.Configuration.LoggingRules.Add(Rule);
|
|
|
|
LogManager.ConfigurationReloaded += OnLogManagerOnConfigurationReloaded;
|
|
|
|
LogManager.ConfigurationChanged += OnLogManagerOnConfigurationChanged;
|
|
|
|
LogManager.ReconfigExistingLoggers();
|
|
|
|
LogManager.ReconfigExistingLoggers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UnRegister()
|
|
|
|
public void UnRegister()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LogManager.ConfigurationReloaded -= OnLogManagerOnConfigurationReloaded;
|
|
|
|
LogManager.ConfigurationChanged -= OnLogManagerOnConfigurationChanged;
|
|
|
|
LogManager.Configuration.RemoveTarget("DbLogger");
|
|
|
|
LogManager.Configuration.RemoveTarget("DbLogger");
|
|
|
|
LogManager.Configuration.LoggingRules.Remove(Rule);
|
|
|
|
LogManager.Configuration.LoggingRules.Remove(Rule);
|
|
|
|
LogManager.ReconfigExistingLoggers();
|
|
|
|
LogManager.ReconfigExistingLoggers();
|
|
|
|
Dispose();
|
|
|
|
Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnLogManagerOnConfigurationReloaded(object sender, LoggingConfigurationReloadedEventArgs args)
|
|
|
|
private void OnLogManagerOnConfigurationChanged(object sender, LoggingConfigurationChangedEventArgs args)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (args.ActivatedConfiguration != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Register();
|
|
|
|
Register();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LoggingRule Rule { get; set; }
|
|
|
|
public LoggingRule Rule { get; set; }
|
|
|
|
|
|
|
|
|
|
|
@ -97,9 +100,14 @@ namespace NzbDrone.Core.Instrumentation
|
|
|
|
WritePostgresLog(log, connectionString);
|
|
|
|
WritePostgresLog(log, connectionString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (NpgsqlException ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
InternalLogger.Error("Unable to save log event to database: {0}", ex);
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (SQLiteException ex)
|
|
|
|
catch (SQLiteException ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
InternalLogger.Error(ex, "Unable to save log event to database");
|
|
|
|
InternalLogger.Error("Unable to save log event to database: {0}", ex);
|
|
|
|
throw;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -128,10 +136,8 @@ namespace NzbDrone.Core.Instrumentation
|
|
|
|
private void WriteSqliteLog(Log log, string connectionString)
|
|
|
|
private void WriteSqliteLog(Log log, string connectionString)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var connection =
|
|
|
|
using (var connection =
|
|
|
|
SQLiteFactory.Instance.CreateConnection())
|
|
|
|
new SQLiteConnection(connectionString).OpenAndReturn())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
connection.ConnectionString = connectionString;
|
|
|
|
|
|
|
|
connection.Open();
|
|
|
|
|
|
|
|
using (var sqlCommand = connection.CreateCommand())
|
|
|
|
using (var sqlCommand = connection.CreateCommand())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sqlCommand.CommandText = INSERT_COMMAND;
|
|
|
|
sqlCommand.CommandText = INSERT_COMMAND;
|
|
|
|