fix log, added UrlShortenerService config

This commit is contained in:
pavelbannov 2020-05-21 11:03:35 +03:00
parent 02dd1e9e31
commit 3fadf8db6c
5 changed files with 29 additions and 16 deletions

View File

@ -26,7 +26,7 @@ namespace ASC.Common.DependencyInjection
public static class AutofacExtension
{
public static IContainer AddAutofac(this IServiceCollection services, IConfiguration configuration, string currentDir, bool loadproducts = true, params string[] intern)
public static IContainer AddAutofac(this IServiceCollection services, IConfiguration configuration, string currentDir, bool loadproducts = true, bool loadconsumers = true, params string[] intern)
{
var folder = configuration["core:products:folder"];
var subfolder = configuration["core:products:subfolder"];
@ -44,8 +44,7 @@ namespace ASC.Common.DependencyInjection
var builder = new ContainerBuilder();
var modules = new List<(bool, string)>
{
(true, "autofac.json"),
(true, "autofac.consumers.json")
(true, "autofac.json")
};
if (loadproducts)
@ -53,6 +52,11 @@ namespace ASC.Common.DependencyInjection
modules.Add((true, "autofac.products.json"));
}
if (loadconsumers)
{
modules.Add((true, "autofac.consumers.json"));
}
if (intern != null)
{
modules.AddRange(intern.Select(r => (false, r)));

View File

@ -372,7 +372,7 @@ namespace ASC.Common.Logging
public string Dir { get; set; }
}
public class ConfigureLogNLog : IConfigureOptions<LogNLog>
public class ConfigureLogNLog : IConfigureNamedOptions<LogNLog>
{
public ConfigureLogNLog(IConfiguration configuration)
{
@ -397,7 +397,12 @@ namespace ASC.Common.Logging
}
NLog.Targets.Target.Register<SelfCleaningTarget>("SelfCleaning");
}
}
public void Configure(string name, LogNLog options)
{
Configure(options);
}
}
public class LogNLog : ILog
@ -658,7 +663,7 @@ namespace ASC.Common.Logging
if (IsFatalEnabled) Loger.Fatal(provider, format, args);
}
public string LogDirectory { get { return NLog.LogManager.Configuration.Variables["logDirectory"].Text; } }
public string LogDirectory { get { return NLog.LogManager.Configuration.Variables["dir"].Text; } }
private string name;
public string Name
@ -886,6 +891,7 @@ namespace ASC.Common.Logging
public static DIHelper AddNLogManager(this DIHelper services, params string[] additionalLoggers)
{
services.TryAddSingleton<IConfigureNamedOptions<LogNLog>, ConfigureLogNLog>();
services.TryAddSingleton<IConfigureOptions<LogNLog>, ConfigureLogNLog>();
return services.AddLogManager<LogNLog>(additionalLoggers);
}

View File

@ -61,12 +61,11 @@ namespace ASC.UrlShortener.Svc
}
)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env}.json", true)
.AddJsonFile($"appsettings.services.json", true)
.AddJsonFile("storage.json")
.AddJsonFile("notify.json")
.AddJsonFile("kafka.json")
.AddJsonFile($"kafka.{env}.json", true)
.AddJsonFile($"appsettings.{env}.json", true)
.AddJsonFile($"urlshortener.{env}.json", true)
.AddJsonFile("storage.json")
.AddJsonFile("kafka.json")
.AddJsonFile($"kafka.{env}.json", true)
.AddEnvironmentVariables();
})
.ConfigureServices((hostContext, services) =>
@ -76,7 +75,7 @@ namespace ASC.UrlShortener.Svc
services.AddHostedService<UrlShortenerServiceLauncher>();
diHelper.AddUrlShortenerServiceLauncher();
services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath, new string[] { "autofac.json" });
services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath, false, false);
})
.UseConsoleLifetime()
.Build();

View File

@ -103,7 +103,6 @@ namespace ASC.UrlShortener.Svc
{
var path = configuration["urlshortener:path"] ?? "../../ASC.UrlShortener/index.js";
var port = configuration["urlshortener:port"] ?? "9999";
var logPath = configuration["urlshortener:log"] ?? "../../../Logs/urlshortener.log";
var startInfo = new ProcessStartInfo
{
@ -115,7 +114,7 @@ namespace ASC.UrlShortener.Svc
WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory
};
startInfo.EnvironmentVariables.Add("core.machinekey", configuration["core:machinekey"]);
startInfo.EnvironmentVariables.Add("core:machinekey", configuration["core:machinekey"]);
startInfo.EnvironmentVariables.Add("port", port);
@ -141,7 +140,7 @@ namespace ASC.UrlShortener.Svc
}
}
startInfo.EnvironmentVariables.Add("logPath", Path.GetFullPath(Path.Combine(hostEnvironment.ContentRootPath, logPath)));
startInfo.EnvironmentVariables.Add("logPath", Path.GetFullPath(Path.Combine(hostEnvironment.ContentRootPath, log.LogDirectory, "web.urlshortener.log")));
return startInfo;
}

View File

@ -0,0 +1,5 @@
{
"urlshortener": {
"path": "../client/index.js"
}
}