Use Postgresql, add db run params, npgsql logging adapter and empty models
This commit is contained in:
parent
3425896c0b
commit
d2f31d0730
24 changed files with 252 additions and 39 deletions
12
Geekbot.net/Lib/Extensions/LongExtensions.cs
Normal file
12
Geekbot.net/Lib/Extensions/LongExtensions.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
namespace Geekbot.net.Lib.Extensions
|
||||
{
|
||||
public static class LongExtensions
|
||||
{
|
||||
public static ulong AsUlong(this long thing)
|
||||
{
|
||||
return Convert.ToUInt64(thing);
|
||||
}
|
||||
}
|
||||
}
|
12
Geekbot.net/Lib/Extensions/UlongExtensions.cs
Normal file
12
Geekbot.net/Lib/Extensions/UlongExtensions.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
namespace Geekbot.net.Lib.Extensions
|
||||
{
|
||||
public static class UlongExtensions
|
||||
{
|
||||
public static long AsLong(this ulong thing)
|
||||
{
|
||||
return Convert.ToInt64(thing);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -49,6 +49,16 @@ namespace Geekbot.net.Lib.Logger
|
|||
else _logger.Error(stackTrace, CreateLogString("Error", source, message, stackTrace, extra));
|
||||
}
|
||||
|
||||
public NLog.Logger GetNLogger()
|
||||
{
|
||||
return _logger;
|
||||
}
|
||||
|
||||
public bool LogAsJson()
|
||||
{
|
||||
return _logAsJson;
|
||||
}
|
||||
|
||||
private string CreateLogString(string type, LogSource source, string message, Exception stackTrace = null, object extra = null)
|
||||
{
|
||||
if (_logAsJson)
|
||||
|
|
|
@ -9,5 +9,7 @@ namespace Geekbot.net.Lib.Logger
|
|||
void Information(LogSource source, string message, object extra = null);
|
||||
void Warning(LogSource source, string message, Exception stackTrace = null, object extra = null);
|
||||
void Error(LogSource source, string message, Exception stackTrace, object extra = null);
|
||||
NLog.Logger GetNLogger();
|
||||
bool LogAsJson();
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ namespace Geekbot.net.Lib.Logger
|
|||
Gateway,
|
||||
Discord,
|
||||
Redis,
|
||||
Database,
|
||||
Message,
|
||||
UserRepository,
|
||||
Command,
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace Geekbot.net.Lib.Logger
|
|||
{
|
||||
var minLevel = runParameters.Verbose ? LogLevel.Trace : LogLevel.Info;
|
||||
config.LoggingRules.Add(
|
||||
new LoggingRule("*", LogLevel.Info, LogLevel.Fatal,
|
||||
new LoggingRule("*", minLevel, LogLevel.Fatal,
|
||||
new ColoredConsoleTarget
|
||||
{
|
||||
Name = "Console",
|
||||
|
|
|
@ -5,6 +5,9 @@ namespace Geekbot.net.Lib
|
|||
{
|
||||
public class RunParameters
|
||||
{
|
||||
/**
|
||||
* General Parameters
|
||||
*/
|
||||
[Option('V', "verbose", Default = false, HelpText = "Prints all messages to standard output.")]
|
||||
public bool Verbose { get; set; }
|
||||
|
||||
|
@ -23,7 +26,26 @@ namespace Geekbot.net.Lib
|
|||
[Option("token", Default = null, HelpText = "Set a new bot token")]
|
||||
public string Token { get; set; }
|
||||
|
||||
[Option("in-memory", Default = false, HelpText = "Disables the web api")]
|
||||
/**
|
||||
* Database Stuff
|
||||
*/
|
||||
[Option("in-memory", Default = false, HelpText = "Uses the in-memory database instead of postgresql")]
|
||||
public bool InMemory { get; set; }
|
||||
|
||||
// Postresql connection
|
||||
[Option("database", Default = false, HelpText = "Select a postgresql database")]
|
||||
public string DbDatabase { get; set; } = "geekbot";
|
||||
|
||||
[Option("db-host", Default = false, HelpText = "Set a postgresql host (e.g. 127.0.0.1)")]
|
||||
public string DbHost { get; set; } = "localhost";
|
||||
|
||||
[Option("db-port", Default = false, HelpText = "Set a postgresql host (e.g. 5432)")]
|
||||
public string DbPort { get; set; } = "5432";
|
||||
|
||||
[Option("db-user", Default = false, HelpText = "Set a postgresql user")]
|
||||
public string DbUser { get; set; } = "geekbot";
|
||||
|
||||
[Option("db-password", Default = false, HelpText = "Set a posgresql password")]
|
||||
public string DbPassword { get; set; } = "";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue