Updated
This commit is contained in:
@@ -1,118 +1,120 @@
|
||||
using EonaCat.Logger.Managers;
|
||||
using System.IO.Compression;
|
||||
using System.IO.Compression;
|
||||
using EonaCat.Logger.EonaCatCoreLogger;
|
||||
using EonaCat.Logger.Extensions;
|
||||
using EonaCat.Logger.Managers;
|
||||
|
||||
namespace EonaCat.Logger.Test.Web
|
||||
namespace EonaCat.Logger.Test.Web;
|
||||
|
||||
public static class Logger
|
||||
{
|
||||
public static class Logger
|
||||
private static LogManager LogManager;
|
||||
public static ELogType MinLogType { get; set; }
|
||||
public static bool UseLocalTime { get; set; }
|
||||
public static string LogFolder => Path.Combine(FileLoggerOptions.DefaultPath, "logs");
|
||||
public static string CurrentLogFile => LogManager.CurrentLogFile;
|
||||
public static bool IsDisabled { get; set; }
|
||||
|
||||
public static void DeleteCurrentLogFile()
|
||||
{
|
||||
public static ELogType MaxLogType { get; set; }
|
||||
public static bool UseLocalTime { get; set; }
|
||||
private static LogManager LogManager;
|
||||
public static string LogFolder => "Logs";
|
||||
public static string CurrentLogFile => LogManager.CurrentLogFile;
|
||||
public static bool IsDisabled { get; set; }
|
||||
if (IsDisabled)
|
||||
return;
|
||||
|
||||
public static void DeleteCurrentLogFile()
|
||||
LogManager.DeleteCurrentLogFile();
|
||||
}
|
||||
|
||||
private static string ConvertToAbsolutePath(string path)
|
||||
{
|
||||
return Path.IsPathRooted(path) ? path : Path.Combine(LogFolder, path);
|
||||
}
|
||||
|
||||
public static async Task DownloadLogAsync(HttpContext context, string logName, long limit)
|
||||
{
|
||||
var logFileName = logName + ".log";
|
||||
|
||||
await using var fS = new FileStream(Path.Combine(ConvertToAbsolutePath(LogFolder), logFileName), FileMode.Open,
|
||||
FileAccess.Read, FileShare.ReadWrite, 64 * 1024, true);
|
||||
var response = context.Response;
|
||||
|
||||
response.ContentType = "text/plain";
|
||||
response.Headers.ContentDisposition = "attachment;filename=" + logFileName;
|
||||
|
||||
if (limit > fS.Length || limit < 1)
|
||||
limit = fS.Length;
|
||||
|
||||
var oFS = new OffsetStream(fS, 0, limit);
|
||||
var request = context.Request;
|
||||
Stream stream;
|
||||
|
||||
string acceptEncoding = request.Headers["Accept-Encoding"];
|
||||
if (string.IsNullOrEmpty(acceptEncoding))
|
||||
{
|
||||
if (IsDisabled)
|
||||
return;
|
||||
|
||||
LogManager.DeleteCurrentLogFile();
|
||||
stream = response.Body;
|
||||
}
|
||||
|
||||
private static string ConvertToAbsolutePath(string path)
|
||||
else
|
||||
{
|
||||
return Path.IsPathRooted(path) ? path : Path.Combine(LogFolder, path);
|
||||
}
|
||||
var acceptEncodingParts = acceptEncoding.Split(new[] { ',' },
|
||||
StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
public static async Task DownloadLogAsync(HttpContext context, string logName, long limit)
|
||||
{
|
||||
var logFileName = logName + ".log";
|
||||
|
||||
await using var fS = new FileStream(Path.Combine(ConvertToAbsolutePath(LogFolder), logFileName), FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 64 * 1024, true);
|
||||
var response = context.Response;
|
||||
|
||||
response.ContentType = "text/plain";
|
||||
response.Headers.ContentDisposition = "attachment;filename=" + logFileName;
|
||||
|
||||
if ((limit > fS.Length) || (limit < 1))
|
||||
limit = fS.Length;
|
||||
|
||||
var oFS = new OffsetStream(fS, 0, limit);
|
||||
var request = context.Request;
|
||||
Stream stream;
|
||||
|
||||
string acceptEncoding = request.Headers["Accept-Encoding"];
|
||||
if (string.IsNullOrEmpty(acceptEncoding))
|
||||
if (acceptEncodingParts.Contains("br"))
|
||||
{
|
||||
stream = response.Body;
|
||||
response.Headers.ContentEncoding = "br";
|
||||
stream = new BrotliStream(response.Body, CompressionMode.Compress);
|
||||
}
|
||||
else if (acceptEncodingParts.Contains("gzip"))
|
||||
{
|
||||
response.Headers.ContentEncoding = "gzip";
|
||||
stream = new GZipStream(response.Body, CompressionMode.Compress);
|
||||
}
|
||||
else if (acceptEncodingParts.Contains("deflate"))
|
||||
{
|
||||
response.Headers.ContentEncoding = "deflate";
|
||||
stream = new DeflateStream(response.Body, CompressionMode.Compress);
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] acceptEncodingParts = acceptEncoding.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
if (acceptEncodingParts.Contains("br"))
|
||||
{
|
||||
response.Headers.ContentEncoding = "br";
|
||||
stream = new BrotliStream(response.Body, CompressionMode.Compress);
|
||||
}
|
||||
else if (acceptEncodingParts.Contains("gzip"))
|
||||
{
|
||||
response.Headers.ContentEncoding = "gzip";
|
||||
stream = new GZipStream(response.Body, CompressionMode.Compress);
|
||||
}
|
||||
else if (acceptEncodingParts.Contains("deflate"))
|
||||
{
|
||||
response.Headers.ContentEncoding = "deflate";
|
||||
stream = new DeflateStream(response.Body, CompressionMode.Compress);
|
||||
}
|
||||
else
|
||||
{
|
||||
stream = response.Body;
|
||||
}
|
||||
}
|
||||
|
||||
await using (stream)
|
||||
{
|
||||
await oFS.CopyToAsync(stream).ConfigureAwait(false);
|
||||
|
||||
if (fS.Length > limit)
|
||||
await stream.WriteAsync("\r\n####__EONACATLOGGER_TRUNCATED___####"u8.ToArray()).ConfigureAwait(false);
|
||||
stream = response.Body;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Log(string message, ELogType logType = ELogType.INFO, bool writeToConsole = true)
|
||||
await using (stream)
|
||||
{
|
||||
if (IsDisabled)
|
||||
return;
|
||||
await oFS.CopyToAsync(stream).ConfigureAwait(false);
|
||||
|
||||
LogManager.Write(message, logType, writeToConsole);
|
||||
}
|
||||
|
||||
public static void Log(Exception exception, string message = "", bool writeToConsole = true)
|
||||
{
|
||||
if (IsDisabled)
|
||||
return;
|
||||
|
||||
LogManager.Write(exception, module: message, writeToConsole: writeToConsole);
|
||||
}
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
var loggerSettings = new LoggerSettings
|
||||
{
|
||||
Id = "EonaCatDnsLogger",
|
||||
MaxLogType = ELogType.TRACE,
|
||||
UseLocalTime = UseLocalTime,
|
||||
FileLoggerOptions =
|
||||
{
|
||||
LogDirectory = "Logs",
|
||||
FileSizeLimit = 20_000_000, // 20 MB,
|
||||
UseLocalTime = UseLocalTime,
|
||||
}
|
||||
};
|
||||
LogManager = new LogManager(loggerSettings);
|
||||
if (fS.Length > limit)
|
||||
await stream.WriteAsync("\r\n####__EONACATLOGGER_TRUNCATED___####"u8.ToArray()).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Log(string message, ELogType logType = ELogType.INFO, bool writeToConsole = true)
|
||||
{
|
||||
if (IsDisabled)
|
||||
return;
|
||||
|
||||
LogManager.Write(message, logType, writeToConsole);
|
||||
}
|
||||
|
||||
public static void Log(Exception exception, string message = "", bool writeToConsole = true)
|
||||
{
|
||||
if (IsDisabled)
|
||||
return;
|
||||
|
||||
LogManager.Write(exception, message, writeToConsole: writeToConsole);
|
||||
}
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
var loggerSettings = new LoggerSettings
|
||||
{
|
||||
Id = "EonaCatTestLogger",
|
||||
MinLogType = ELogType.INFO,
|
||||
UseLocalTime = UseLocalTime,
|
||||
FileLoggerOptions =
|
||||
{
|
||||
LogDirectory = LogFolder,
|
||||
FileSizeLimit = 20_000_000, // 20 MB,
|
||||
UseLocalTime = UseLocalTime
|
||||
}
|
||||
};
|
||||
LogManager = new LogManager(loggerSettings);
|
||||
}
|
||||
}
|
||||
@@ -23,4 +23,4 @@
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
||||
</p>
|
||||
@@ -1,27 +1,26 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace EonaCat.Logger.Web.Pages
|
||||
namespace EonaCat.Logger.Web.Pages;
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class ErrorModel : PageModel
|
||||
{
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class ErrorModel : PageModel
|
||||
private readonly ILogger<ErrorModel> _logger;
|
||||
|
||||
public ErrorModel(ILogger<ErrorModel> logger)
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
private readonly ILogger<ErrorModel> _logger;
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
public ErrorModel(ILogger<ErrorModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
}
|
||||
public void OnGet()
|
||||
{
|
||||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
}
|
||||
}
|
||||
@@ -7,4 +7,4 @@
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Welcome</h1>
|
||||
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,19 +1,17 @@
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace EonaCat.Logger.Web.Pages
|
||||
namespace EonaCat.Logger.Web.Pages;
|
||||
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
public class IndexModel : PageModel
|
||||
private readonly ILogger<IndexModel> _logger;
|
||||
|
||||
public IndexModel(ILogger<IndexModel> logger)
|
||||
{
|
||||
private readonly ILogger<IndexModel> _logger;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IndexModel(ILogger<IndexModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
|
||||
}
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -5,4 +5,4 @@
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<p>Use this page to detail your site's privacy policy.</p>
|
||||
<p>Use this page to detail your site's privacy policy.</p>
|
||||
@@ -1,19 +1,17 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace EonaCat.Logger.Web.Pages
|
||||
namespace EonaCat.Logger.Web.Pages;
|
||||
|
||||
public class PrivacyModel : PageModel
|
||||
{
|
||||
public class PrivacyModel : PageModel
|
||||
private readonly ILogger<PrivacyModel> _logger;
|
||||
|
||||
public PrivacyModel(ILogger<PrivacyModel> logger)
|
||||
{
|
||||
private readonly ILogger<PrivacyModel> _logger;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public PrivacyModel(ILogger<PrivacyModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>@ViewData["Title"] - EonaCat.Logger.Web</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/EonaCat.Logger.Web.styles.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
|
||||
<link rel="stylesheet" href="~/EonaCat.Logger.Web.styles.css" asp-append-version="true"/>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-page="/Index">EonaCat.Logger.Web</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
© 2022 - EonaCat.Logger.Web - <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
<a class="navbar-brand" asp-area="" asp-page="/Index">EonaCat.Logger.Web</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2022 - EonaCat.Logger.Web - <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
|
||||
@await RenderSectionAsync("Scripts", false)
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,2 +1,2 @@
|
||||
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
|
||||
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
|
||||
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
|
||||
@@ -1,3 +1,3 @@
|
||||
@using EonaCat.Logger.Web
|
||||
@namespace EonaCat.Logger.Web.Pages
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@@ -1,3 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,11 @@ using EonaCat.Web.Tracer.Extensions;
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
FileLoggerOptions options = new FileLoggerOptions();
|
||||
var options = new FileLoggerOptions();
|
||||
options.MaxRolloverFiles = 5;
|
||||
options.FileSizeLimit = 1 * 1024 * 1024 / 4;
|
||||
options.UseLocalTime = true;
|
||||
builder.Logging.AddEonaCatFileLogger(fileLoggerOptions: options, filenamePrefix:"web");
|
||||
builder.Logging.AddEonaCatFileLogger(fileLoggerOptions: options, filenamePrefix: "web");
|
||||
|
||||
builder.Services.AddRazorPages();
|
||||
|
||||
@@ -35,6 +35,7 @@ rateOptions.AddDefaultConfiguration(config =>
|
||||
);
|
||||
|
||||
RateLimiterMiddleware.OnLimitResponseCreated += RateLimiterMiddlewareOnLimitResponseCreatedAsync;
|
||||
|
||||
async void RateLimiterMiddlewareOnLimitResponseCreatedAsync(object? sender, HttpContext httpContext)
|
||||
{
|
||||
await httpContext.Response.WriteAsync(" THIS IS MY CUSTOM RATE LIMIT MESSAGE").ConfigureAwait(false);
|
||||
@@ -61,7 +62,7 @@ builder.Services.AddMemoryCache();
|
||||
var app = builder.Build();
|
||||
|
||||
Logger.UseLocalTime = true;
|
||||
Logger.MaxLogType = ELogType.TRACE;
|
||||
Logger.MinLogType = ELogType.TRACE;
|
||||
Logger.Configure();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
@@ -83,6 +84,7 @@ if (!app.Environment.IsDevelopment())
|
||||
// await httpContext.Response.WriteAsync("THIS IS MY CUSTOM RATE LIMIT MESSAGE");
|
||||
//}
|
||||
WebTracer.OnLog += WebTracer_OnLog;
|
||||
|
||||
void WebTracer_OnLog(object? sender, string e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
@@ -103,10 +105,10 @@ void RunLoggingExceptionTests()
|
||||
var loggerSettings = new LoggerSettings();
|
||||
loggerSettings.FileLoggerOptions.UseLocalTime = true;
|
||||
loggerSettings.UseLocalTime = true;
|
||||
loggerSettings.MaxLogType = ELogType.TRACE;
|
||||
loggerSettings.MinLogType = ELogType.INFO;
|
||||
var logger = new LogManager(loggerSettings);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -117,19 +119,20 @@ void RunLoggingExceptionTests()
|
||||
logger.Write(exception);
|
||||
Console.WriteLine($"Normal ExceptionLogged: {i}");
|
||||
}
|
||||
|
||||
Task.Delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
Task.Run(RunWebLoggerTests);
|
||||
Task.Run(RunWebLoggingTests);
|
||||
//Task.Run(RunWebLoggerTests);
|
||||
//Task.Run(RunWebLoggingTests);
|
||||
Task.Run(RunLoggingTests);
|
||||
Task.Run(RunLoggingExceptionTests);
|
||||
Task.Run(RunWebLoggingExceptionTests);
|
||||
//Task.Run(RunLoggingExceptionTests);
|
||||
//Task.Run(RunWebLoggingExceptionTests);
|
||||
|
||||
void RunWebLoggingExceptionTests()
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -145,18 +148,16 @@ void RunWebLoggingExceptionTests()
|
||||
app.Logger.LogInformation(exception, "INFORMATION");
|
||||
Console.WriteLine($"WebExceptionLogged: {i}");
|
||||
}
|
||||
|
||||
Task.Delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void RunWebLoggingTests()
|
||||
{
|
||||
if (!Directory.Exists(Logger.LogFolder))
|
||||
{
|
||||
Directory.CreateDirectory(Logger.LogFolder);
|
||||
}
|
||||
if (!Directory.Exists(Logger.LogFolder)) Directory.CreateDirectory(Logger.LogFolder);
|
||||
|
||||
for (int i = 0; i < 9000000; i++)
|
||||
for (var i = 0; i < 9000000; i++)
|
||||
{
|
||||
app.Logger.LogInformation($"web-test {i}");
|
||||
File.AppendAllText(Path.Combine(Logger.LogFolder, "test.log"), $"WebLogged: {i}{Environment.NewLine}");
|
||||
@@ -170,15 +171,15 @@ void RunLoggingTests()
|
||||
var loggerSettings = new LoggerSettings();
|
||||
loggerSettings.UseLocalTime = true;
|
||||
loggerSettings.FileLoggerOptions.UseLocalTime = true;
|
||||
loggerSettings.MaxLogType = ELogType.TRACE;
|
||||
loggerSettings.MinLogType = ELogType.INFO;
|
||||
loggerSettings.FileLoggerOptions.FileSizeLimit = 1024 * 1024 * 1;
|
||||
loggerSettings.FileLoggerOptions.FileNamePrefix = "AllTypes";
|
||||
loggerSettings.FileLoggerOptions.MaxRolloverFiles = 5;
|
||||
var logger = new LogManager(loggerSettings);
|
||||
|
||||
for (int i = 0; i < 9000000; i++)
|
||||
for (var i = 0; i < 9000000; i++)
|
||||
{
|
||||
logger.Write($"test to file {i} INFO", ELogType.INFO);
|
||||
logger.Write($"test to file {i} INFO");
|
||||
logger.Write($"test to file {i} CRITICAL", ELogType.CRITICAL);
|
||||
logger.Write($"test to file {i} DEBUG", ELogType.DEBUG);
|
||||
logger.Write($"test to file {i} ERROR", ELogType.ERROR);
|
||||
@@ -193,9 +194,9 @@ void RunLoggingTests()
|
||||
|
||||
void RunWebLoggerTests()
|
||||
{
|
||||
for (int i = 0; i < 9000000; i++)
|
||||
for (var i = 0; i < 9000000; i++)
|
||||
{
|
||||
Logger.Log($"test via logger {i} INFO", ELogType.INFO);
|
||||
Logger.Log($"test via logger {i} INFO");
|
||||
Logger.Log($"test via logger {i} CRITICAL", ELogType.CRITICAL);
|
||||
Logger.Log($"test via logger {i} DEBUG", ELogType.DEBUG);
|
||||
Logger.Log($"test via logger {i} ERROR", ELogType.ERROR);
|
||||
@@ -208,4 +209,4 @@ void RunWebLoggerTests()
|
||||
}
|
||||
}
|
||||
|
||||
app.Run();
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user