Modify "WriteLine" with "_log".

When creating StartupLog, it configures itself.
This commit is contained in:
Javier Pastor 2019-11-25 13:02:46 +01:00
commit c915512c1a
2 changed files with 28 additions and 11 deletions

View file

@ -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"))
{

View file

@ -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);
}
}
}
}