From c915512c1aebda4569eac4598ce62b7f1eb4f8bb Mon Sep 17 00:00:00 2001 From: Javier Pastor Date: Mon, 25 Nov 2019 13:02:46 +0100 Subject: [PATCH] Modify "WriteLine" with "_log". When creating StartupLog, it configures itself. --- src/Ombi/Program.cs | 9 +++------ src/Ombi/StartupLog.cs | 30 +++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/Ombi/Program.cs b/src/Ombi/Program.cs index 3d207ef6e..1933eba86 100644 --- a/src/Ombi/Program.cs +++ b/src/Ombi/Program.cs @@ -20,7 +20,7 @@ namespace Ombi public class Program { private static string UrlArgs { get; set; } - private static StartupLog _log = new StartupLog(); + private static StartupLog _log = new StartupLog(true); public static void Main(string[] args) { @@ -41,7 +41,7 @@ namespace Ombi { foreach (var e in err) { - Console.WriteLine(e); + _log.LogError(e); } }); @@ -58,7 +58,6 @@ namespace Ombi DeleteSchedules(); //CheckAndMigrate(); - _log.Config(); var services = new ServiceCollection(); services.ConfigureDatabases(); using (var provider = services.BuildServiceProvider()) @@ -128,10 +127,8 @@ namespace Ombi } } - Console.WriteLine($"We are running on {urlValue}"); - + _log.LogInformation($"We are running on {urlValue}"); CreateWebHostBuilder(args).Build().Run(); - } catch (MySql.Data.MySqlClient.MySqlException e) when (e.SqlState.Equals("28000") || e.SqlState.Equals("42000")) { diff --git a/src/Ombi/StartupLog.cs b/src/Ombi/StartupLog.cs index ae4a6e9ef..9f4de8ab6 100644 --- a/src/Ombi/StartupLog.cs +++ b/src/Ombi/StartupLog.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Serilog; using ILogger = Serilog.ILogger; using Ombi.Helpers; - +using CommandLine; namespace Ombi { @@ -20,16 +20,24 @@ namespace Ombi get { return Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.Substring(0, Assembly.GetEntryAssembly().Location.IndexOf("bin\\"))); } } - public StartupLog() + private string ContentLogsPath { - //this.config(); + get { return Path.Combine(StoragePath.StoragePath.IsNullOrEmpty() ? this.ContentRootPath : StoragePath.StoragePath, "Logs"); } + } + + public StartupLog(bool autoconf = false) + { + if (autoconf == true) + { + this.Config(); + } } public void Config() { ILogger log_config = new LoggerConfiguration() .MinimumLevel.Debug() - .WriteTo.RollingFile(Path.Combine(StoragePath.StoragePath.IsNullOrEmpty() ? this.ContentRootPath : StoragePath.StoragePath, "Logs", "startup-{Date}.txt")) + .WriteTo.RollingFile(Path.Combine(this.ContentLogsPath, "startup-{Date}.txt")) .CreateLogger(); Log.Logger = log_config; } @@ -40,10 +48,22 @@ namespace Ombi Log.Error(str); } + internal void LogError(Error e) + { + Console.WriteLine(e); + Log.Error(e.ToString()); + } + public void LogInformation(string str) { Console.WriteLine(str); Log.Information(str); } + + public void LogVerbose(string str) + { + Console.WriteLine(str); + Log.Verbose(str); + } } -} +} \ No newline at end of file