DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
LoggerFactory.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include <mutex>
3#include <vector>
6
7namespace DotNetDupe {
8 namespace Extensions {
9 namespace Logging {
10
11 struct LoggerFactory::Impl {
12 std::vector<DotNetDupe::System::SmartPointer<ILoggerProvider>> pProviders;
13 std::mutex mutex;
14 };
15
17 : m_pImpl(DotNetDupe::System::SmartPointer<Impl>::NewShared()) {
19 }
20
22
25 if (pProvider.IsNull()) return;
26
28 std::lock_guard<std::mutex> lock(m_pImpl->mutex);
29 m_pImpl->pProviders.push_back(pProvider);
30 }
31
34 std::lock_guard<std::mutex> lock(m_pImpl->mutex);
36
38 for (auto& pProvider : m_pImpl->pProviders) {
39 auto pLogger = pProvider->CreateLogger(categoryName);
40 if (!pLogger.IsNull()) {
41 pAggregate->AddLogger(pLogger);
42 }
43 }
44
46 return pAggregate;
47 }
48
49 }
50 }
51}
void AddProvider(const DotNetDupe::System::SmartPointer< ILoggerProvider > &pProvider) override
Adds an ILoggerProvider backend to the factory.
DotNetDupe::System::SmartPointer< ILogger > CreateLogger(const DotNetDupe::System::String &categoryName) override
Creates a new ILogger instance for the specified category.
LoggerFactory()
Initializes a new LoggerFactory instance.
~LoggerFactory() override
Virtual destructor cleaning up registered providers.
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.
Definition String.h:74