-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Solution - Add and used Logger. * WathList.Test - Chang the initialization of class instances to new ones. * Solution - Fixed Linter. * Solution: WatchList.Core - Add class AggregateLogging. * Solution: WatchList.WinForms - Changed contain DI.
- Loading branch information
1 parent
97a8f97
commit e3aa8a6
Showing
20 changed files
with
279 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace WatchList.Core.Logger | ||
{ | ||
public class AggregateLogging : List<ILogger>, ILogger | ||
{ | ||
private readonly LogLevel _logLevel; | ||
Check warning on line 7 in WatchList.Core/Logger/AggregateLogging.cs GitHub Actions / build
|
||
|
||
public AggregateLogging() | ||
: base() | ||
{ | ||
} | ||
|
||
public AggregateLogging(int capacity) | ||
: base(capacity) | ||
{ | ||
} | ||
|
||
public AggregateLogging(IEnumerable<ILogger> collection) | ||
: base(collection) | ||
{ | ||
} | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) | ||
{ | ||
foreach (var loggin in this) | ||
{ | ||
loggin.Log(logLevel, eventId, state, exception, formatter); | ||
} | ||
} | ||
|
||
public bool IsEnabled(LogLevel logLevel) => _logLevel <= logLevel; | ||
|
||
public IDisposable? BeginScope<TState>(TState state) | ||
where TState : notnull | ||
=> new Disposable(); | ||
|
||
private sealed class Disposable : IDisposable | ||
{ | ||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace WatchList.Core.Logger | ||
{ | ||
public sealed class ConsoleLogger : ILogger | ||
{ | ||
private readonly LogLevel _logLevel; | ||
|
||
public ConsoleLogger(LogLevel logLevel) => _logLevel = logLevel; | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) | ||
{ | ||
if (!IsEnabled(logLevel)) | ||
{ | ||
return; | ||
} | ||
|
||
var message = formatter(state, exception); | ||
Console.WriteLine("[{0} {1:G}] {2}", logLevel, DateTime.Now, message); | ||
} | ||
|
||
public bool IsEnabled(LogLevel logLevel) => _logLevel <= logLevel; | ||
|
||
public IDisposable? BeginScope<TState>(TState state) | ||
where TState : notnull | ||
=> new Disposable(); | ||
|
||
private sealed class Disposable : IDisposable | ||
{ | ||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Globalization; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace WatchList.Core.Logger | ||
{ | ||
public sealed class FileLogger : ILogger | ||
{ | ||
private readonly LogLevel _logLevel; | ||
private readonly string _pathFileLog; | ||
|
||
public FileLogger(LogLevel logLevel, string pathFileLog) | ||
{ | ||
_logLevel = logLevel; | ||
_pathFileLog = pathFileLog; | ||
} | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) | ||
{ | ||
if (!IsEnabled(logLevel)) | ||
{ | ||
return; | ||
} | ||
|
||
var message = formatter(state, exception); | ||
var logText = string.Format("[{0} {1:G}] {2}", logLevel, DateTime.Now, message); | ||
File.AppendAllText(BuildPath(), logText + Environment.NewLine); | ||
} | ||
|
||
public bool IsEnabled(LogLevel logLevel) => _logLevel <= logLevel; | ||
|
||
public IDisposable? BeginScope<TState>(TState state) | ||
where TState : notnull | ||
=> new Disposable(); | ||
|
||
private string BuildPath() | ||
{ | ||
var dateStr = DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); | ||
return Path.Combine(_pathFileLog, dateStr + ".txt"); | ||
} | ||
|
||
private sealed class Disposable : IDisposable | ||
{ | ||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace WatchList.Test.CoreTest | ||
{ | ||
public sealed class TestLogger : ILogger | ||
{ | ||
private readonly LogLevel _logLevel; | ||
|
||
public TestLogger(LogLevel logLevel = LogLevel.Trace) => _logLevel = logLevel; | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) | ||
{ | ||
if (!IsEnabled(logLevel)) | ||
{ | ||
return; | ||
} | ||
|
||
var message = formatter(state, exception); | ||
} | ||
|
||
public bool IsEnabled(LogLevel logLevel) => _logLevel <= logLevel; | ||
|
||
public IDisposable? BeginScope<TState>(TState state) | ||
where TState : notnull | ||
=> new Disposable(); | ||
|
||
private sealed class Disposable : IDisposable | ||
{ | ||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.