chore(config): NLog-Konfiguration aus WebApiConfig entfernt
This commit is contained in:
parent
197db1e08b
commit
a55b4c5f63
@ -1,8 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace HRD.WebApi
|
||||
{
|
||||
@ -18,17 +16,6 @@ namespace HRD.WebApi
|
||||
{
|
||||
private static string _dalConnectionstring;
|
||||
|
||||
internal static LogLevel GetMonitoringWebRequestLevel(string method, string path)
|
||||
{
|
||||
var entity = NlogMonitoringWebRequest.FirstOrDefault(
|
||||
x => x.WebRequestMethod.Equals(method, StringComparison.OrdinalIgnoreCase) &&
|
||||
(x.WebRequestPath == "*" || path.StartsWith(x.WebRequestPath, StringComparison.OrdinalIgnoreCase))
|
||||
);
|
||||
if (entity == default)
|
||||
return LogLevel.None;
|
||||
return entity.LoggingLevel;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> _customConfig = new Dictionary<string, string>();
|
||||
|
||||
public static int ConnectionstringTimeoutInMin { get; set; } = 5;
|
||||
@ -44,32 +31,6 @@ namespace HRD.WebApi
|
||||
OfficeFileServerUrl = appSettings["AppConfig:OfficeFileServerUrl"];
|
||||
IsLive = bool.Parse(appSettings["AppConfig:LDAP_WebAppGroup_Is_Live"]);
|
||||
|
||||
//LDAP
|
||||
//LDAPService.LdapGlobals.LDAP_WebAppGroup_Is_Live = IsLive;
|
||||
|
||||
//Nlog
|
||||
NlogConnectionstring = appSettings["Nlog:NlogConnectionstring"];
|
||||
if (NlogConnectionstring.Equals("%sqlConnection%", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
NlogConnectionstring = appSettings["ConnectionStrings:sqlConnection"];
|
||||
}
|
||||
|
||||
NlogDBLogLevel = ToEnumLoggingLevel(appSettings["Nlog:NlogDBLogLevel"]);
|
||||
NlogFileLogLevel = ToEnumLoggingLevel(appSettings["Nlog:NlogFileLogLevel"]);
|
||||
NlogLogDirectory = appSettings["Nlog:NlogLogDirectory"];
|
||||
NlogSentryDSN = appSettings["Nlog:NlogSentryDSN"];
|
||||
NlogSentryIsEnable = bool.Parse(appSettings["Nlog:NlogSentryIsEnable"]);
|
||||
|
||||
for (int i = 1; i < 100; i++)
|
||||
{
|
||||
string configString = appSettings[$"Nlog:MonitoringWebRequest{i}"];
|
||||
if (!string.IsNullOrEmpty(configString))
|
||||
{
|
||||
string[] configArr = configString.Split("|").Select(x => x.Trim()).ToArray();
|
||||
NlogMonitoringWebRequest.Add(new MonitoringWebRequest { WebRequestMethod = configArr[0], WebRequestPath = configArr[1], LoggingLevel = ToEnumLoggingLevel(configArr[2]) });
|
||||
}
|
||||
}
|
||||
|
||||
//custom
|
||||
var list = appSettings.GetSection("CustomConfig").GetChildren();
|
||||
foreach (var item in list)
|
||||
@ -119,42 +80,6 @@ namespace HRD.WebApi
|
||||
public static string ClientVersion { get; set; }
|
||||
public static bool IsLive { get; set; }
|
||||
|
||||
//Logger
|
||||
public static List<MonitoringWebRequest> NlogMonitoringWebRequest { get; set; } = new List<MonitoringWebRequest>();
|
||||
|
||||
public static string NlogLogDirectory { get; set; } = string.Empty;
|
||||
|
||||
public static string NlogSentryDSN { get; set; } = string.Empty;
|
||||
public static bool NlogSentryIsEnable { get; set; } = true;
|
||||
|
||||
public static string NlogConnectionstring { get; set; }
|
||||
public static LogLevel NlogFileLogLevel { get; set; } = LogLevel.Error;
|
||||
public static LogLevel NlogDBLogLevel { get; set; } = LogLevel.Error;
|
||||
|
||||
public static DbContextOptions<DbContext> SQLOptions()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Connectionstring))
|
||||
{
|
||||
throw new NullReferenceException("Connectnion string is empty!");
|
||||
}
|
||||
var optionsBuilder = new DbContextOptionsBuilder<DbContext>();
|
||||
optionsBuilder
|
||||
.EnableDetailedErrors()
|
||||
.UseSqlServer(Connectionstring,
|
||||
opts =>
|
||||
{
|
||||
opts.CommandTimeout((int)TimeSpan.FromMinutes(ConnectionstringTimeoutInMin).TotalSeconds);
|
||||
opts.EnableRetryOnFailure(
|
||||
maxRetryCount: 5,
|
||||
maxRetryDelay: TimeSpan.FromSeconds(30),
|
||||
errorNumbersToAdd: null
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return optionsBuilder.Options;
|
||||
}
|
||||
|
||||
public static string ConnectionString(EN_ConnectionType connectionType = EN_ConnectionType.SQLServer)
|
||||
{
|
||||
switch (connectionType)
|
||||
|
||||
@ -4,10 +4,6 @@ namespace HRD.WebApi.DAL
|
||||
{
|
||||
public abstract class WebApiBaseContext : DbContext
|
||||
{
|
||||
public WebApiBaseContext() : base(WebApiConfig.SQLOptions())
|
||||
{
|
||||
}
|
||||
|
||||
public WebApiBaseContext(DbContextOptions options)
|
||||
: base(options)
|
||||
{
|
||||
|
||||
@ -21,35 +21,5 @@ namespace HRD.WebApi.DAL.Middleware
|
||||
_next = next;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task InvokeAsync(HttpContext httpContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var loglevel = WebApiConfig.GetMonitoringWebRequestLevel(httpContext.Request.Method, httpContext.Request.Path.Value);
|
||||
if (loglevel == LogLevel.Information
|
||||
|| loglevel == LogLevel.Warning
|
||||
|| loglevel == LogLevel.Error
|
||||
)
|
||||
{
|
||||
var requestReader = new StreamReader(httpContext.Request.Body);
|
||||
var requestContent = await requestReader.ReadToEndAsync();
|
||||
if (string.IsNullOrEmpty(requestContent))
|
||||
{
|
||||
requestContent = $"{httpContext.Request.Method} {httpContext.Request.Path.Value}";
|
||||
}
|
||||
|
||||
if (loglevel == LogLevel.Information) { _logger.LogInformation(requestContent); }
|
||||
if (loglevel == LogLevel.Warning) { _logger.LogWarning(requestContent); }
|
||||
if (loglevel == LogLevel.Error) { _logger.LogError(requestContent); }
|
||||
}
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
//throw;
|
||||
}
|
||||
|
||||
await _next(httpContext).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -27,10 +27,6 @@ namespace HRD.WebApi.DAL.Middleware
|
||||
WebApiConfig.AssemblyName = options.AssemblyName;
|
||||
WebApiConfig.ClientVersion = options.ClientVersion;
|
||||
WebApiConfig.Connectionstring = options.Connectionstring;
|
||||
WebApiConfig.NlogConnectionstring = options.NlogConnectionstring;
|
||||
WebApiConfig.NlogDBLogLevel = options.NlogDBLogLevel;
|
||||
WebApiConfig.NlogFileLogLevel = options.NlogFileLogLevel;
|
||||
WebApiConfig.NlogLogDirectory = options.NlogLogDirectory;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,13 +10,5 @@ namespace HRD.WebApi.DAL.Middleware
|
||||
public string ClientVersion { get; set; }
|
||||
|
||||
public string Connectionstring { get; set; } = String.Empty;
|
||||
|
||||
//Logger
|
||||
public string NlogLogDirectory { get; set; } = String.Empty;
|
||||
|
||||
public string NlogConnectionstring { get; set; } = String.Empty;
|
||||
|
||||
public LogLevel NlogFileLogLevel { get; set; } = LogLevel.Error;
|
||||
public LogLevel NlogDBLogLevel { get; set; } = LogLevel.Error;
|
||||
}
|
||||
}
|
||||
@ -12,13 +12,7 @@ namespace StaffDBServer.SharedExtensions
|
||||
AssemblyVersion = WebApiConfig.AssemblyVersion,
|
||||
AssemblyName = WebApiConfig.AssemblyName,
|
||||
ClientVersion = WebApiConfig.ClientVersion,
|
||||
|
||||
Connectionstring = WebApiConfig.Connectionstring,
|
||||
|
||||
NlogConnectionstring = WebApiConfig.NlogConnectionstring,
|
||||
NlogDBLogLevel = WebApiConfig.NlogDBLogLevel,
|
||||
NlogFileLogLevel = WebApiConfig.NlogFileLogLevel,
|
||||
NlogLogDirectory = WebApiConfig.NlogLogDirectory
|
||||
Connectionstring = WebApiConfig.Connectionstring
|
||||
};
|
||||
return options;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user