DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
LoggerFactory.cpp
Go to the documentation of this file.
1
#include "
pch.h
"
2
#include <mutex>
3
#include <vector>
4
#include "
Extensions/Logging/LoggerFactory.h
"
5
#include "
Extensions/Logging/AggregateLogger.h
"
6
7
namespace
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
16
LoggerFactory::LoggerFactory
()
17
: m_pImpl(
DotNetDupe
::
System
::SmartPointer<Impl>::NewShared()) {
19
}
20
21
LoggerFactory::~LoggerFactory
() =
default
;
22
23
void
LoggerFactory::AddProvider
(
const
DotNetDupe::System::SmartPointer<ILoggerProvider>
& pProvider) {
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
32
DotNetDupe::System::SmartPointer<ILogger>
LoggerFactory::CreateLogger
(
const
DotNetDupe::System::String
& categoryName) {
34
std::lock_guard<std::mutex> lock(m_pImpl->mutex);
35
auto
pAggregate =
DotNetDupe::System::SmartPointer<AggregateLogger>::NewShared
();
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
}
AggregateLogger.h
LoggerFactory.h
DotNetDupe::Extensions::Logging::LoggerFactory::AddProvider
void AddProvider(const DotNetDupe::System::SmartPointer< ILoggerProvider > &pProvider) override
Adds an ILoggerProvider backend to the factory.
Definition
LoggerFactory.cpp:23
DotNetDupe::Extensions::Logging::LoggerFactory::CreateLogger
DotNetDupe::System::SmartPointer< ILogger > CreateLogger(const DotNetDupe::System::String &categoryName) override
Creates a new ILogger instance for the specified category.
Definition
LoggerFactory.cpp:32
DotNetDupe::Extensions::Logging::LoggerFactory::LoggerFactory
LoggerFactory()
Initializes a new LoggerFactory instance.
Definition
LoggerFactory.cpp:16
DotNetDupe::Extensions::Logging::LoggerFactory::~LoggerFactory
~LoggerFactory() override
Virtual destructor cleaning up registered providers.
DotNetDupe::System::SmartPointer
A unified smart pointer that supports both unique and shared ownership semantics.
Definition
SmartPointer.h:72
DotNetDupe::System::SmartPointer::NewShared
static SmartPointer< T > NewShared()
Creates a Shared SmartPointer, default constructing T.
Definition
SmartPointer.h:277
DotNetDupe::System::SmartPointer::IsNull
bool IsNull() const noexcept
Checks if the SmartPointer is null.
Definition
SmartPointer.h:393
DotNetDupe::System::String
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition
String.h:74
DotNetDupe::Extensions::Logging
Definition
AggregateLogger.h:8
DotNetDupe::Extensions
Definition
IServiceCollection.h:8
DotNetDupe::System
Definition
Action.h:11
DotNetDupe
Definition
IServiceCollection.h:7
pch.h
DotNetDupe
LoggerFactory.cpp
Generated by
1.18.0