log db queries
This commit is contained in:
@@ -12,19 +12,22 @@ namespace ReallifeGamemode.Database.Models
|
|||||||
{
|
{
|
||||||
public partial class DatabaseContext : DbContext
|
public partial class DatabaseContext : DbContext
|
||||||
{
|
{
|
||||||
private readonly ILoggerFactory loggerFactory;
|
public static ILoggerFactory LoggerFactory { get; set; }
|
||||||
|
|
||||||
public DatabaseContext(ILoggerFactory loggerFactory = null) {
|
private readonly bool useLoggerFactory = false;
|
||||||
this.loggerFactory = loggerFactory;
|
|
||||||
|
public DatabaseContext(bool useLoggerFactory = false)
|
||||||
|
{
|
||||||
|
this.useLoggerFactory = useLoggerFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
base.OnConfiguring(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");
|
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.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using ReallifeGamemode.Database.Models;
|
using ReallifeGamemode.Database.Models;
|
||||||
using ReallifeGamemode.Server.Core.API;
|
using ReallifeGamemode.Server.Core.API;
|
||||||
@@ -26,6 +27,8 @@ namespace ReallifeGamemode.Server.Core
|
|||||||
API = api;
|
API = api;
|
||||||
EventHandler = eventHandler;
|
EventHandler = eventHandler;
|
||||||
|
|
||||||
|
DatabaseContext.LoggerFactory = LogManager.Factory;
|
||||||
|
|
||||||
API.DisableDefaultCommandErrorMessages();
|
API.DisableDefaultCommandErrorMessages();
|
||||||
API.DisableDefaultSpawnBehavior();
|
API.DisableDefaultSpawnBehavior();
|
||||||
API.SetGlobalChatEnabled(false);
|
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
|
internal static TScript GetScript<TScript>() where TScript : Script
|
||||||
|
|||||||
@@ -43,8 +43,6 @@ namespace ReallifeGamemode.Server
|
|||||||
[ServerEvent(Event.ResourceStart)]
|
[ServerEvent(Event.ResourceStart)]
|
||||||
public void OnResourceStart()
|
public void OnResourceStart()
|
||||||
{
|
{
|
||||||
System.Console.WriteLine(System.DateTime.Now.ToShortTimeString());
|
|
||||||
|
|
||||||
var methods = Assembly.GetExecutingAssembly()
|
var methods = Assembly.GetExecutingAssembly()
|
||||||
.GetTypes()
|
.GetTypes()
|
||||||
.SelectMany(t => t.GetMethods())
|
.SelectMany(t => t.GetMethods())
|
||||||
|
|||||||
Reference in New Issue
Block a user