log db queries
This commit is contained in:
@@ -12,19 +12,22 @@ namespace ReallifeGamemode.Database.Models
|
||||
{
|
||||
public partial class DatabaseContext : DbContext
|
||||
{
|
||||
private readonly ILoggerFactory loggerFactory;
|
||||
public static ILoggerFactory LoggerFactory { get; set; }
|
||||
|
||||
public DatabaseContext(ILoggerFactory loggerFactory = null) {
|
||||
this.loggerFactory = loggerFactory;
|
||||
private readonly bool useLoggerFactory = false;
|
||||
|
||||
public DatabaseContext(bool useLoggerFactory = false)
|
||||
{
|
||||
this.useLoggerFactory = useLoggerFactory;
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
|
||||
if(loggerFactory != null)
|
||||
if (useLoggerFactory && LoggerFactory != null)
|
||||
{
|
||||
optionsBuilder.UseLoggerFactory(loggerFactory);
|
||||
optionsBuilder.UseLoggerFactory(LoggerFactory);
|
||||
}
|
||||
|
||||
optionsBuilder.UseMySql("Host=localhost;Port=3306;Database=gtav-devdb;Username=gtav-dev;Password=Test123");
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
@@ -26,6 +27,8 @@ namespace ReallifeGamemode.Server.Core
|
||||
API = api;
|
||||
EventHandler = eventHandler;
|
||||
|
||||
DatabaseContext.LoggerFactory = LogManager.Factory;
|
||||
|
||||
API.DisableDefaultCommandErrorMessages();
|
||||
API.DisableDefaultSpawnBehavior();
|
||||
API.SetGlobalChatEnabled(false);
|
||||
@@ -61,9 +64,9 @@ namespace ReallifeGamemode.Server.Core
|
||||
}
|
||||
}
|
||||
|
||||
public static DatabaseContext GetDbContext(bool useLoggerFactory = true)
|
||||
public static DatabaseContext GetDbContext(bool useLoggerFactory = false)
|
||||
{
|
||||
return new DatabaseContext(useLoggerFactory ? LogManager.Factory : null);
|
||||
return new DatabaseContext(useLoggerFactory);
|
||||
}
|
||||
|
||||
internal static TScript GetScript<TScript>() where TScript : Script
|
||||
|
||||
@@ -43,8 +43,6 @@ namespace ReallifeGamemode.Server
|
||||
[ServerEvent(Event.ResourceStart)]
|
||||
public void OnResourceStart()
|
||||
{
|
||||
System.Console.WriteLine(System.DateTime.Now.ToShortTimeString());
|
||||
|
||||
var methods = Assembly.GetExecutingAssembly()
|
||||
.GetTypes()
|
||||
.SelectMany(t => t.GetMethods())
|
||||
|
||||
Reference in New Issue
Block a user