DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
ConsoleLogger.cpp
Go to the documentation of this file.
1#include "pch.h"
3#include "System/Console.h"
4#include <iostream>
5
6namespace DotNetDupe {
7 namespace Extensions {
8 namespace Logging {
9
11 : LoggerBase(categoryName, config) {
13 }
14
17 LoggerBase::Log(logLevel, message);
18 }
19
23 if (!IsEnabled(logLevel)) return;
24
26 DotNetDupe::System::String sFormatted = BuildLogMessage(logLevel, message, properties);
27
29 if (!DotNetDupe::System::Console::Out().IsNull()) {
30 std::cout << sFormatted.GetRawString() << std::endl;
31 } else {
33 }
34 }
35
36 }
37 }
38}
Represents standard input, output, and error streams for console applications.
ConsoleLogger(const DotNetDupe::System::String &categoryName, const LoggerConfiguration &config)
Initializes a new instance of ConsoleLogger with category name and configuration.
void Log(LogLevel logLevel, const DotNetDupe::System::String &message) override
Writes a log entry to the console.
void Log(LogLevel logLevel, const DotNetDupe::System::String &message) override
Writes a log entry without extra structured properties.
bool IsEnabled(LogLevel logLevel) const override
Checks whether logging is enabled for the specified log level.
DotNetDupe::System::String BuildLogMessage(LogLevel logLevel, const DotNetDupe::System::String &message, const DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > &properties) const
Builds the final log message string applying plain text or JSON serialization.
LoggerBase(const DotNetDupe::System::String &categoryName, const LoggerConfiguration &config)
Initializes a new LoggerBase instance with category name and configuration.
Represents a collection of keys and values.
Definition Dictionary.h:66
static SmartPointer< IO::TextWriter > Out()
Definition Console.cpp:394
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74
const char * GetRawString() const
Definition String.cpp:230
LogLevel
Defines logging severity levels.
Definition ILogger.h:15
Encapsulates logging system configuration options.