20 auto normalize = [](
const String& s) {
25 for (
int iIdx = 0; raw[iIdx] !=
'\0'; ++iIdx) {
26 if (raw[iIdx] !=
'_') {
31 return String(cleaned.c_str());
34 String targetNormalized = normalize(targetName);
38 for (
int iIdx = 0; iIdx < propNames.GetLength(); ++iIdx) {
39 if (normalize(propNames[iIdx]) == targetNormalized) {
53 struct JsonConverter<DotNetDupe::Extensions::Logging::FileRolloverConfig> {
54 static JsonElement Write(
const DotNetDupe::Extensions::Logging::FileRolloverConfig& value) {
63 static DotNetDupe::Extensions::Logging::FileRolloverConfig Read(
const JsonElement& element) {
66 throw JsonException(
"Expected a JSON object for FileRolloverConfig");
68 DotNetDupe::Extensions::Logging::FileRolloverConfig config;
72 if (TryGetPropertyCaseInsensitive(element,
"EnableRollover", prop)) {
75 if (TryGetPropertyCaseInsensitive(element,
"MaxFileSizeInBytes", prop)) {
78 if (TryGetPropertyCaseInsensitive(element,
"MaxBackupFiles", prop)) {
86 struct JsonConverter<DotNetDupe::Extensions::Logging::LoggerConfiguration> {
87 static JsonElement Write(
const DotNetDupe::Extensions::Logging::LoggerConfiguration& value) {
90 const char* pMinLevelStr =
"Information";
108 obj.SetProperty(
"Rollover", JsonConverter<DotNetDupe::Extensions::Logging::FileRolloverConfig>::Write(value.
Rollover));
112 static DotNetDupe::Extensions::Logging::LoggerConfiguration Read(
const JsonElement& element) {
115 throw JsonException(
"Expected a JSON object for LoggerConfiguration");
117 DotNetDupe::Extensions::Logging::LoggerConfiguration config;
121 if (TryGetPropertyCaseInsensitive(element,
"MinLevel", prop)) {
127 throw JsonException(
"Invalid type for MinLevel in LoggerConfiguration");
132 if (TryGetPropertyCaseInsensitive(element,
"IsJsonFormat", prop)) {
135 if (TryGetPropertyCaseInsensitive(element,
"PlainTextFormat", prop)) {
138 if (TryGetPropertyCaseInsensitive(element,
"TimestampFormat", prop)) {
141 if (TryGetPropertyCaseInsensitive(element,
"FilePath", prop)) {
144 if (TryGetPropertyCaseInsensitive(element,
"Rollover", prop)) {
145 config.
Rollover = JsonConverter<DotNetDupe::Extensions::Logging::FileRolloverConfig>::Read(prop);
165 static const struct {
const char* pName;
LogLevel eLevel; } s_mappings[] = {
175 for (
const auto& mapping : s_mappings) {
176 if (sLower == mapping.pName)
return mapping.eLevel;
Defines the exception thrown when an invalid argument is provided to a method.
Provides static methods for the creation, copying, deletion, moving, and opening of a single file.
The exception that is thrown when an I/O error occurs.
Exception thrown when invalid JSON payload or token is encountered per RFC 8259.
Provides functionality to serialize objects to JSON strings and deserialize JSON strings into objects...
The exception that is thrown when one of the arguments provided to a method is not valid.
static bool Exists(const String &sPath)
Determines whether the specified file exists.
static String ReadAllText(const String &sPath)
Opens a text file, reads all the text in the file, and then closes the file.
The exception that is thrown when an I/O error occurs.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
String()
Initializes a new instance of the String class to an empty string.
const char * GetRawString() const
Represents a specific JSON value within a JsonDocument or object hierarchy.
Array< String > GetPropertyNames() const
Gets an array containing the names of all properties on the current JSON object.
JsonValueKind GetValueKind() const
Gets the type of the current JSON value.
bool TryGetProperty(const String &sPropertyName, JsonElement &objValue) const
Looks for a property named propertyName in the current JSON object.
JsonException()
Initializes a new instance of the JsonException class with a default message.
static T Deserialize(const String &sJson)
Parses the text representing a single JSON value into an instance of the type specified by a generic ...
LogLevel
Defines logging severity levels.
@ Warning
Logs that highlight an abnormal or unexpected event.
@ Critical
Logs that describe an unrecoverable application or system crash.
@ None
Not used for writing log messages. Specifies that a logging category should not write any messages.
@ Error
Logs that highlight when the current flow of execution is stopped due to a failure.
@ Debug
Logs that are used for interactive investigation during development.
@ Information
Logs that track the general flow of the application.
@ Trace
Logs that contain the most detailed messages.
LogLevel ParseLogLevel(const DotNetDupe::System::String &str)
Parses a case-insensitive string into a corresponding LogLevel enumeration value.
long long MaxFileSizeInBytes
Maximum size in bytes of the primary log file before rotation (default: 5 MB).
bool EnableRollover
Indicates whether file rotation is enabled when file size threshold is reached.
int MaxBackupFiles
Maximum number of rotated backup log files to retain (default: 3).
Encapsulates logging system configuration options.
static LoggerConfiguration LoadFromFile(const DotNetDupe::System::String &filePath)
Loads logging configuration options from a JSON file.
DotNetDupe::System::String TimestampFormat
Timestamp formatting template using strftime syntax (e.g. "%Y-%m-%d %H:%M:%S").
DotNetDupe::System::String FilePath
Destination file path when file logging is configured.
bool IsJsonFormat
Specifies whether to serialize log messages as structured JSON objects.
DotNetDupe::System::String PlainTextFormat
Plain text formatting template (e.g. "{Timestamp} [{Level}] [{Category}] {Message}...
FileRolloverConfig Rollover
File rotation settings.
static LoggerConfiguration LoadFromJson(const DotNetDupe::System::String &jsonContent)
Loads logging configuration options from a raw JSON string.
LogLevel MinLevel
Minimum log level required for a message to be recorded.
static JsonElement Write(const String &value)
static String Read(const JsonElement &element)
static bool Read(const JsonElement &element)
static JsonElement Write(const bool &value)
static JsonElement Write(const int &value)
static int Read(const JsonElement &element)
static long long Read(const JsonElement &element)
static JsonElement Write(const long long &value)
Primary template for type-specific JSON serialization converters.