Revert "chore(config): NLog-Konfiguration aus WebApiConfig entfernt"
This reverts commit a55b4c5f63b9cc68a0279867fa744aa998f8826d.
This commit is contained in:
parent
381f428f77
commit
dddc01d24c
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace HRD.WebApi
|
namespace HRD.WebApi
|
||||||
{
|
{
|
||||||
@ -16,6 +18,17 @@ namespace HRD.WebApi
|
|||||||
{
|
{
|
||||||
private static string _dalConnectionstring;
|
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>();
|
private static Dictionary<string, string> _customConfig = new Dictionary<string, string>();
|
||||||
|
|
||||||
public static int ConnectionstringTimeoutInMin { get; set; } = 5;
|
public static int ConnectionstringTimeoutInMin { get; set; } = 5;
|
||||||
@ -31,6 +44,32 @@ namespace HRD.WebApi
|
|||||||
OfficeFileServerUrl = appSettings["AppConfig:OfficeFileServerUrl"];
|
OfficeFileServerUrl = appSettings["AppConfig:OfficeFileServerUrl"];
|
||||||
IsLive = bool.Parse(appSettings["AppConfig:LDAP_WebAppGroup_Is_Live"]);
|
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
|
//custom
|
||||||
var list = appSettings.GetSection("CustomConfig").GetChildren();
|
var list = appSettings.GetSection("CustomConfig").GetChildren();
|
||||||
foreach (var item in list)
|
foreach (var item in list)
|
||||||
@ -80,6 +119,42 @@ namespace HRD.WebApi
|
|||||||
public static string ClientVersion { get; set; }
|
public static string ClientVersion { get; set; }
|
||||||
public static bool IsLive { 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)
|
public static string ConnectionString(EN_ConnectionType connectionType = EN_ConnectionType.SQLServer)
|
||||||
{
|
{
|
||||||
switch (connectionType)
|
switch (connectionType)
|
||||||
|
|||||||
@ -4,6 +4,10 @@ namespace HRD.WebApi.DAL
|
|||||||
{
|
{
|
||||||
public abstract class WebApiBaseContext : DbContext
|
public abstract class WebApiBaseContext : DbContext
|
||||||
{
|
{
|
||||||
|
public WebApiBaseContext() : base(WebApiConfig.SQLOptions())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public WebApiBaseContext(DbContextOptions options)
|
public WebApiBaseContext(DbContextOptions options)
|
||||||
: base(options)
|
: base(options)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -21,5 +21,35 @@ namespace HRD.WebApi.DAL.Middleware
|
|||||||
_next = next;
|
_next = next;
|
||||||
_logger = logger;
|
_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,6 +27,10 @@ namespace HRD.WebApi.DAL.Middleware
|
|||||||
WebApiConfig.AssemblyName = options.AssemblyName;
|
WebApiConfig.AssemblyName = options.AssemblyName;
|
||||||
WebApiConfig.ClientVersion = options.ClientVersion;
|
WebApiConfig.ClientVersion = options.ClientVersion;
|
||||||
WebApiConfig.Connectionstring = options.Connectionstring;
|
WebApiConfig.Connectionstring = options.Connectionstring;
|
||||||
|
WebApiConfig.NlogConnectionstring = options.NlogConnectionstring;
|
||||||
|
WebApiConfig.NlogDBLogLevel = options.NlogDBLogLevel;
|
||||||
|
WebApiConfig.NlogFileLogLevel = options.NlogFileLogLevel;
|
||||||
|
WebApiConfig.NlogLogDirectory = options.NlogLogDirectory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -10,5 +10,13 @@ namespace HRD.WebApi.DAL.Middleware
|
|||||||
public string ClientVersion { get; set; }
|
public string ClientVersion { get; set; }
|
||||||
|
|
||||||
public string Connectionstring { get; set; } = String.Empty;
|
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,7 +12,13 @@ namespace StaffDBServer.SharedExtensions
|
|||||||
AssemblyVersion = WebApiConfig.AssemblyVersion,
|
AssemblyVersion = WebApiConfig.AssemblyVersion,
|
||||||
AssemblyName = WebApiConfig.AssemblyName,
|
AssemblyName = WebApiConfig.AssemblyName,
|
||||||
ClientVersion = WebApiConfig.ClientVersion,
|
ClientVersion = WebApiConfig.ClientVersion,
|
||||||
Connectionstring = WebApiConfig.Connectionstring
|
|
||||||
|
Connectionstring = WebApiConfig.Connectionstring,
|
||||||
|
|
||||||
|
NlogConnectionstring = WebApiConfig.NlogConnectionstring,
|
||||||
|
NlogDBLogLevel = WebApiConfig.NlogDBLogLevel,
|
||||||
|
NlogFileLogLevel = WebApiConfig.NlogFileLogLevel,
|
||||||
|
NlogLogDirectory = WebApiConfig.NlogLogDirectory
|
||||||
};
|
};
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user