9#include <unordered_map>
17 static std::mutex s_mutex;
19 static DotNetDupe::System::SmartPointer<LoggerFactory> s_pFactory =
nullptr;
20 static DotNetDupe::System::SmartPointer<ConsoleLoggerProvider> s_pConsoleProvider =
nullptr;
21 static DotNetDupe::System::SmartPointer<FileLoggerProvider> s_pFileProvider =
nullptr;
22 static std::unordered_map<std::string, DotNetDupe::System::SmartPointer<ILogger>> s_pLoggerCache;
23 static std::unordered_map<std::string, DotNetDupe::System::SmartPointer<ILogger>> s_pConsoleLoggerCache;
24 static std::unordered_map<std::string, DotNetDupe::System::SmartPointer<ILogger>> s_pFileLoggerCache;
26 void EnsureFactoryInitializedLocked() {
32 s_pFactory->AddProvider(s_pConsoleProvider);
33 s_pFactory->AddProvider(s_pFileProvider);
40 std::lock_guard<std::mutex> lk(s_mutex);
44 auto it = s_pLoggerCache.find(sKey);
45 if (it != s_pLoggerCache.end()) {
50 EnsureFactoryInitializedLocked();
51 auto pLogger = s_pFactory->CreateLogger(sCategoryName);
52 s_pLoggerCache[sKey] = pLogger;
58 std::lock_guard<std::mutex> lk(s_mutex);
62 auto it = s_pConsoleLoggerCache.find(sKey);
63 if (it != s_pConsoleLoggerCache.end()) {
68 EnsureFactoryInitializedLocked();
69 auto pLogger = s_pConsoleProvider->CreateLogger(sCategoryName);
70 s_pConsoleLoggerCache[sKey] = pLogger;
76 std::lock_guard<std::mutex> lk(s_mutex);
80 auto it = s_pFileLoggerCache.find(sKey);
81 if (it != s_pFileLoggerCache.end()) {
86 EnsureFactoryInitializedLocked();
87 auto pLogger = s_pFileProvider->CreateLogger(sCategoryName);
88 s_pFileLoggerCache[sKey] = pLogger;
94 std::lock_guard<std::mutex> lk(s_mutex);
95 s_globalConfig = config;
96 s_pLoggerCache.clear();
97 s_pConsoleLoggerCache.clear();
98 s_pFileLoggerCache.clear();
104 s_pFactory->AddProvider(s_pConsoleProvider);
105 s_pFactory->AddProvider(s_pFileProvider);
110 std::lock_guard<std::mutex> lk(s_mutex);
111 return s_globalConfig;
116 if (pProvider.
IsNull())
return;
119 std::lock_guard<std::mutex> lk(s_mutex);
120 EnsureFactoryInitializedLocked();
121 s_pFactory->AddProvider(pProvider);
122 s_pLoggerCache.clear();
127 std::lock_guard<std::mutex> lk(s_mutex);
129 s_pLoggerCache.clear();
130 s_pConsoleLoggerCache.clear();
131 s_pFileLoggerCache.clear();
132 s_pConsoleProvider =
nullptr;
133 s_pFileProvider =
nullptr;
134 s_pFactory =
nullptr;
static DotNetDupe::System::SmartPointer< ILogger > GetConsoleLogger(const DotNetDupe::System::String &sCategoryName)
Creates a dedicated ConsoleLogger instance for the specified category.
static void Reset()
Resets the LogManager state, releasing all cached loggers and providers.
static DotNetDupe::System::SmartPointer< ILogger > GetFileLogger(const DotNetDupe::System::String &sCategoryName)
Creates a dedicated FileLogger instance for the specified category.
static const LoggerConfiguration & GetConfiguration()
Gets the active global LoggerConfiguration.
static void AddProvider(const DotNetDupe::System::SmartPointer< ILoggerProvider > &pProvider)
Adds an ILoggerProvider to the internal global LoggerFactory.
static DotNetDupe::System::SmartPointer< ILoggerOf< T > > GetLogger()
Retrieves a strongly-typed ILoggerOf<T> where the category name is derived from type T.
static void Configure(const LoggerConfiguration &config)
Sets the global LoggerConfiguration applied across created loggers.
A unified smart pointer that supports both unique and shared ownership semantics.
static SmartPointer< T > NewShared()
Creates a Shared SmartPointer, default constructing T.
bool IsNull() const noexcept
Checks if the SmartPointer is null.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
const char * GetRawString() const
Encapsulates logging system configuration options.