30 Log(logLevel, message, emptyProps);
35 auto now = std::chrono::system_clock::now();
36 auto time = std::chrono::system_clock::to_time_t(now);
39 gmtime_s(&buf, &time);
41 gmtime_r(&time, &buf);
45 char timeStr[255] = { 0 };
46 size_t written = std::strftime(timeStr,
sizeof(timeStr), sFmt.c_str(), &buf);
62 default:
return "None";
66 static void ReplaceToken(std::string& str,
const std::string& from,
const char* to) {
69 std::string sTo = to ? to :
"";
70 while ((pos = str.find(from, pos)) != std::string::npos) {
71 str.replace(pos, from.length(), sTo);
78 auto keys = properties.
GetKeys();
79 for (
int iIdx = 0; iIdx < keys.GetLength(); ++iIdx) {
81 std::string placeholder =
"{" + std::string(key.
GetRawString()) +
"}";
82 if (str.find(placeholder) != std::string::npos) {
93 if (properties.
GetCount() == 0)
return "";
95 auto keys = properties.
GetKeys();
99 for (
int iIdx = 0; iIdx < keys.GetLength(); ++iIdx) {
100 std::string k = keys[iIdx].GetRawString();
101 if (std::find(usedKeys.begin(), usedKeys.end(), k) != usedKeys.end())
continue;
102 if (!bFirst) ss <<
", ";
126 if (properties.
GetCount() == 0)
return;
128 auto keys = properties.
GetKeys();
131 for (
int iIdx = 0; iIdx < keys.GetLength(); ++iIdx) {
169 std::vector<std::string> usedKeys;
173 std::string sProcId = std::to_string(procId);
174 std::string sThreadId = std::to_string(threadId);
Represents a specific JSON value within a JsonDocument.
Provides access to local and remote processes and enables you to start and stop local system processe...
Creates and controls a thread, sets its priority, and gets its status mirroring .NET System....
DotNetDupe::System::String m_categoryName
DotNetDupe::System::String FormatLogLine(const DotNetDupe::System::String &fmt, const DotNetDupe::System::String ×tamp, const DotNetDupe::System::String &level, const DotNetDupe::System::String &category, const DotNetDupe::System::String &message, const DotNetDupe::System::String &properties, const DotNetDupe::System::String &processId, const DotNetDupe::System::String &threadId) const
Formats a single log line according to configuration template.
void Log(LogLevel logLevel, const DotNetDupe::System::String &message) override
Writes a log entry without extra structured properties.
const char * LogLevelToString(LogLevel level) const
Converts a LogLevel enumeration to its uppercase string name.
bool IsEnabled(LogLevel logLevel) const override
Checks whether logging is enabled for the specified log level.
DotNetDupe::System::String GetFormattedTimestamp(const DotNetDupe::System::String &formatFmt) const
Generates a formatted timestamp string using strftime syntax.
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.
LoggerConfiguration m_config
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.
Array< TKey > GetKeys() const
bool TryGetValue(const TKey &key, TValue &value) const
static int GetCurrentProcessId()
Gets the process identifier of the calling process.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
const char * GetRawString() const
Represents a specific JSON value within a JsonDocument or object hierarchy.
String ToString() const
Serializes the element into a JSON string representation.
void SetProperty(const String &sPropertyName, const JsonElement &objValue)
Sets or replaces a property on the current JSON object.
static int GetCurrentThreadId()
Returns an integer identifier for the current managed thread.
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.
static void AddJsonLogProperties(DotNetDupe::System::Text::Json::JsonElement &logObj, const DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > &properties)
static std::string SerializeUnusedPropertiesText(const DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > &properties, const std::vector< std::string > &usedKeys)
static void ReplaceDynamicPropertyTokens(std::string &str, const DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > &properties, std::vector< std::string > &usedKeys)
static void ReplaceToken(std::string &str, const std::string &from, const char *to)
static DotNetDupe::System::String BuildJsonLog(const DotNetDupe::System::String ×tamp, const char *level, const DotNetDupe::System::String &category, int procId, unsigned long threadId, const DotNetDupe::System::String &message, const DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > &properties)
Encapsulates logging system configuration options.
DotNetDupe::System::String TimestampFormat
Timestamp formatting template using strftime syntax (e.g. "%Y-%m-%d %H:%M:%S").
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}...
LogLevel MinLevel
Minimum log level required for a message to be recorded.