Migrate TraceLogger to runtime class (#772)
This commit is contained in:
@@ -108,7 +108,7 @@ String
|
||||
if (pastedText->Length() > MaxPasteableLength)
|
||||
{
|
||||
// return NoOp to indicate don't paste anything.
|
||||
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"PastedExpressionSizeGreaterThanMaxAllowed");
|
||||
TraceLogger::GetInstance()->LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"PastedExpressionSizeGreaterThanMaxAllowed");
|
||||
return PasteErrorString;
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ String
|
||||
// validate each operand with patterns for different modes
|
||||
if (!ExpressionRegExMatch(operands, mode, modeType, programmerNumberBase, bitLengthType))
|
||||
{
|
||||
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"InvalidExpressionForPresentMode");
|
||||
TraceLogger::GetInstance()->LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"InvalidExpressionForPresentMode");
|
||||
return PasteErrorString;
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression
|
||||
|
||||
if (operands.size() >= MaxOperandCount)
|
||||
{
|
||||
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ExtractOperands", L"OperandCountGreaterThanMaxCount");
|
||||
TraceLogger::GetInstance()->LogError(mode, L"CopyPasteManager::ExtractOperands", L"OperandCountGreaterThanMaxCount");
|
||||
operands.clear();
|
||||
return operands;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression
|
||||
// to disallow pasting of 1e+12345 as 1e+1234, max exponent that can be pasted is 9999.
|
||||
if (expLength > MaxExponentLength)
|
||||
{
|
||||
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ExtractOperands", L"ExponentLengthGreaterThanMaxLength");
|
||||
TraceLogger::GetInstance()->LogError(mode, L"CopyPasteManager::ExtractOperands", L"ExponentLengthGreaterThanMaxLength");
|
||||
operands.clear();
|
||||
return operands;
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ using namespace CalculatorApp;
|
||||
using namespace CalculatorApp::Common;
|
||||
using namespace Concurrency;
|
||||
using namespace std;
|
||||
using namespace Platform;
|
||||
using namespace winrt;
|
||||
using namespace winrt::Windows::Foundation;
|
||||
using namespace winrt::Windows::Foundation::Diagnostics;
|
||||
@@ -57,47 +58,43 @@ namespace CalculatorApp
|
||||
|
||||
TraceLogger::TraceLogger()
|
||||
: g_calculatorProvider(
|
||||
L"MicrosoftCalculator",
|
||||
LoggingChannelOptions(GUID{ 0x4f50731a, 0x89cf, 0x4782, 0xb3, 0xe0, 0xdc, 0xe8, 0xc9, 0x4, 0x76, 0xba }),
|
||||
GUID{ 0x905ca09, 0x610e, 0x401e, 0xb6, 0x50, 0x2f, 0x21, 0x29, 0x80, 0xb9, 0xe0 })
|
||||
L"MicrosoftCalculator",
|
||||
LoggingChannelOptions(GUID{ 0x4f50731a, 0x89cf, 0x4782, 0xb3, 0xe0, 0xdc, 0xe8, 0xc9, 0x4, 0x76, 0xba }),
|
||||
GUID{ 0x905ca09, 0x610e, 0x401e, 0xb6, 0x50, 0x2f, 0x21, 0x29, 0x80, 0xb9, 0xe0 })
|
||||
, // Unique providerID {0905CA09-610E-401E-B650-2F212980B9E0}
|
||||
m_appLaunchActivity{ nullptr }
|
||||
{
|
||||
CoCreateGuid(&sessionGuid);
|
||||
}
|
||||
|
||||
TraceLogger::~TraceLogger()
|
||||
TraceLogger ^ TraceLogger::GetInstance()
|
||||
{
|
||||
}
|
||||
|
||||
TraceLogger& TraceLogger::GetInstance()
|
||||
{
|
||||
static TraceLogger s_selfInstance;
|
||||
static TraceLogger ^ s_selfInstance = ref new TraceLogger();
|
||||
return s_selfInstance;
|
||||
}
|
||||
|
||||
bool TraceLogger::GetTraceLoggingProviderEnabled() const
|
||||
bool TraceLogger::GetTraceLoggingProviderEnabled()
|
||||
{
|
||||
return g_calculatorProvider.Enabled();
|
||||
}
|
||||
|
||||
#pragma region Tracing methods
|
||||
void TraceLogger::LogLevel1Event(wstring_view eventName, LoggingFields fields) const
|
||||
void TraceLogger::LogLevel1Event(wstring_view eventName, LoggingFields fields)
|
||||
{
|
||||
g_calculatorProvider.LogEvent(eventName, fields, LoggingLevel::Verbose, LoggingOptions(MICROSOFT_KEYWORD_LEVEL_1));
|
||||
}
|
||||
|
||||
void TraceLogger::LogLevel2Event(wstring_view eventName, LoggingFields fields) const
|
||||
void TraceLogger::LogLevel2Event(wstring_view eventName, LoggingFields fields)
|
||||
{
|
||||
g_calculatorProvider.LogEvent(eventName, fields, LoggingLevel::Verbose, LoggingOptions(MICROSOFT_KEYWORD_LEVEL_2));
|
||||
}
|
||||
|
||||
void TraceLogger::LogLevel3Event(wstring_view eventName, LoggingFields fields) const
|
||||
void TraceLogger::LogLevel3Event(wstring_view eventName, LoggingFields fields)
|
||||
{
|
||||
g_calculatorProvider.LogEvent(eventName, fields, LoggingLevel::Verbose, LoggingOptions(MICROSOFT_KEYWORD_LEVEL_3));
|
||||
}
|
||||
|
||||
unique_ptr<TraceActivity> TraceLogger::CreateTraceActivity(wstring_view eventName, LoggingFields fields) const
|
||||
unique_ptr<TraceActivity> TraceLogger::CreateTraceActivity(wstring_view eventName, LoggingFields fields)
|
||||
{
|
||||
return make_unique<TraceActivity>(g_calculatorProvider, eventName, fields);
|
||||
}
|
||||
@@ -117,7 +114,7 @@ namespace CalculatorApp
|
||||
return true;
|
||||
}
|
||||
|
||||
void TraceLogger::LogVisualStateChanged(ViewMode mode, wstring_view state, bool isAlwaysOnTop) const
|
||||
void TraceLogger::LogVisualStateChanged(ViewMode mode, String ^ state, bool isAlwaysOnTop)
|
||||
{
|
||||
if (!GetTraceLoggingProviderEnabled())
|
||||
{
|
||||
@@ -127,7 +124,7 @@ namespace CalculatorApp
|
||||
LoggingFields fields{};
|
||||
fields.AddGuid(L"SessionGuid", sessionGuid);
|
||||
fields.AddString(L"CalcMode", NavCategory::GetFriendlyName(mode)->Data());
|
||||
fields.AddString(L"VisualState", state);
|
||||
fields.AddString(L"VisualState", state->Data());
|
||||
fields.AddBoolean(L"IsAlwaysOnTop", isAlwaysOnTop);
|
||||
fields.AddUInt64(PDT_PRIVACY_DATA_TAG, PDT_PRODUCT_AND_SERVICE_USAGE);
|
||||
LogLevel2Event(EVENT_NAME_VISUAL_STATE_CHANGED, fields);
|
||||
@@ -152,7 +149,7 @@ namespace CalculatorApp
|
||||
LogLevel2Event(EVENT_NAME_WINDOW_ON_CREATED, fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogModeChange(ViewMode mode) const
|
||||
void TraceLogger::LogModeChange(ViewMode mode)
|
||||
{
|
||||
if (!GetTraceLoggingProviderEnabled())
|
||||
return;
|
||||
@@ -167,7 +164,7 @@ namespace CalculatorApp
|
||||
}
|
||||
}
|
||||
|
||||
void TraceLogger::LogHistoryItemLoad(ViewMode mode, int historyListSize, int loadedIndex) const
|
||||
void TraceLogger::LogHistoryItemLoad(ViewMode mode, int historyListSize, int loadedIndex)
|
||||
{
|
||||
if (!GetTraceLoggingProviderEnabled())
|
||||
{
|
||||
@@ -183,7 +180,7 @@ namespace CalculatorApp
|
||||
LogLevel2Event(EVENT_NAME_HISTORY_ITEM_LOAD, fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogMemoryItemLoad(ViewMode mode, int memoryListSize, int loadedIndex) const
|
||||
void TraceLogger::LogMemoryItemLoad(ViewMode mode, int memoryListSize, int loadedIndex)
|
||||
{
|
||||
if (!GetTraceLoggingProviderEnabled())
|
||||
{
|
||||
@@ -199,7 +196,7 @@ namespace CalculatorApp
|
||||
LogLevel2Event(EVENT_NAME_MEMORY_ITEM_LOAD, fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogError(ViewMode mode, wstring_view functionName, wstring_view errorString)
|
||||
void TraceLogger::LogError(ViewMode mode, Platform::String ^ functionName, Platform::String ^ errorString)
|
||||
{
|
||||
if (!GetTraceLoggingProviderEnabled())
|
||||
return;
|
||||
@@ -207,13 +204,13 @@ namespace CalculatorApp
|
||||
LoggingFields fields{};
|
||||
fields.AddGuid(L"SessionGuid", sessionGuid);
|
||||
fields.AddString(L"CalcMode", NavCategory::GetFriendlyName(mode)->Data());
|
||||
fields.AddString(L"FunctionName", functionName);
|
||||
fields.AddString(L"Message", errorString);
|
||||
fields.AddString(L"FunctionName", functionName->Data());
|
||||
fields.AddString(L"Message", errorString->Data());
|
||||
fields.AddUInt64(PDT_PRIVACY_DATA_TAG, PDT_PRODUCT_AND_SERVICE_USAGE);
|
||||
LogLevel2Event(EVENT_NAME_EXCEPTION, fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogStandardException(ViewMode mode, wstring_view functionName, const exception& e) const
|
||||
void TraceLogger::LogStandardException(ViewMode mode, wstring_view functionName, const exception& e)
|
||||
{
|
||||
if (!GetTraceLoggingProviderEnabled())
|
||||
return;
|
||||
@@ -229,7 +226,7 @@ namespace CalculatorApp
|
||||
LogLevel2Event(EVENT_NAME_EXCEPTION, fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogWinRTException(ViewMode mode, wstring_view functionName, hresult_error const& e) const
|
||||
void TraceLogger::LogWinRTException(ViewMode mode, wstring_view functionName, hresult_error const& e)
|
||||
{
|
||||
if (!GetTraceLoggingProviderEnabled())
|
||||
return;
|
||||
@@ -244,7 +241,7 @@ namespace CalculatorApp
|
||||
LogLevel2Event(EVENT_NAME_EXCEPTION, fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogPlatformException(ViewMode mode, wstring_view functionName, Platform::Exception ^ e) const
|
||||
void TraceLogger::LogPlatformException(ViewMode mode, wstring_view functionName, Platform::Exception ^ e)
|
||||
{
|
||||
if (!GetTraceLoggingProviderEnabled())
|
||||
return;
|
||||
@@ -291,7 +288,7 @@ namespace CalculatorApp
|
||||
}
|
||||
}
|
||||
|
||||
void TraceLogger::UpdateWindowCount(size_t windowCount)
|
||||
void TraceLogger::UpdateWindowCount(uint64 windowCount)
|
||||
{
|
||||
if (windowCount == 0)
|
||||
{
|
||||
@@ -301,6 +298,11 @@ namespace CalculatorApp
|
||||
currentWindowCount = windowCount;
|
||||
}
|
||||
|
||||
void TraceLogger::DecreaseWindowCount()
|
||||
{
|
||||
currentWindowCount = 0;
|
||||
}
|
||||
|
||||
void TraceLogger::LogButtonUsage()
|
||||
{
|
||||
if (!GetTraceLoggingProviderEnabled())
|
||||
@@ -348,7 +350,7 @@ namespace CalculatorApp
|
||||
LogLevel2Event(EVENT_NAME_DATE_CALCULATION_MODE_USED, fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogConverterInputReceived(ViewMode mode) const
|
||||
void TraceLogger::LogConverterInputReceived(ViewMode mode)
|
||||
{
|
||||
if (!GetTraceLoggingProviderEnabled())
|
||||
return;
|
||||
@@ -360,7 +362,7 @@ namespace CalculatorApp
|
||||
LogLevel2Event(EVENT_NAME_CONVERTER_INPUT_RECEIVED, fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogNavBarOpened() const
|
||||
void TraceLogger::LogNavBarOpened()
|
||||
{
|
||||
if (!GetTraceLoggingProviderEnabled())
|
||||
return;
|
||||
@@ -371,7 +373,7 @@ namespace CalculatorApp
|
||||
LogLevel2Event(EVENT_NAME_NAV_BAR_OPENED, fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogInputPasted(ViewMode mode) const
|
||||
void TraceLogger::LogInputPasted(ViewMode mode)
|
||||
{
|
||||
if (!GetTraceLoggingProviderEnabled())
|
||||
return;
|
||||
|
@@ -28,33 +28,31 @@ namespace CalculatorApp
|
||||
}
|
||||
};
|
||||
|
||||
class TraceLogger
|
||||
public
|
||||
ref class TraceLogger sealed
|
||||
{
|
||||
public:
|
||||
TraceLogger(_In_ TraceLogger const&) = delete;
|
||||
TraceLogger const& operator=(_In_ TraceLogger const&) = delete;
|
||||
~TraceLogger();
|
||||
static TraceLogger& GetInstance();
|
||||
bool GetTraceLoggingProviderEnabled() const;
|
||||
|
||||
void LogModeChange(CalculatorApp::Common::ViewMode mode) const;
|
||||
void LogHistoryItemLoad(CalculatorApp::Common::ViewMode mode, int historyListSize, int loadedIndex) const;
|
||||
void LogMemoryItemLoad(CalculatorApp::Common::ViewMode mode, int memoryListSize, int loadedIndex) const;
|
||||
static TraceLogger ^ GetInstance();
|
||||
bool GetTraceLoggingProviderEnabled();
|
||||
void LogModeChange(CalculatorApp::Common::ViewMode mode);
|
||||
void LogHistoryItemLoad(CalculatorApp::Common::ViewMode mode, int historyListSize, int loadedIndex);
|
||||
void LogMemoryItemLoad(CalculatorApp::Common::ViewMode mode, int memoryListSize, int loadedIndex);
|
||||
void UpdateButtonUsage(CalculatorApp::NumbersAndOperatorsEnum button, CalculatorApp::Common::ViewMode mode);
|
||||
void LogButtonUsage();
|
||||
void LogDateCalculationModeUsed(bool AddSubtractMode);
|
||||
void UpdateWindowCount(size_t windowCount = 0);
|
||||
void UpdateWindowCount(uint64 windowCount);
|
||||
void DecreaseWindowCount();
|
||||
bool IsWindowIdInLog(int windowId);
|
||||
void LogVisualStateChanged(CalculatorApp::Common::ViewMode mode, std::wstring_view state, bool isAlwaysOnTop = false) const;
|
||||
void LogVisualStateChanged(CalculatorApp::Common::ViewMode mode, Platform::String ^ state, bool isAlwaysOnTop);
|
||||
void LogWindowCreated(CalculatorApp::Common::ViewMode mode, int windowId);
|
||||
void LogConverterInputReceived(CalculatorApp::Common::ViewMode mode) const;
|
||||
void LogNavBarOpened() const;
|
||||
|
||||
void LogError(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, std::wstring_view errorString);
|
||||
void LogStandardException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ const std::exception& e) const;
|
||||
void LogWinRTException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ winrt::hresult_error const& e) const;
|
||||
void LogPlatformException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ Platform::Exception ^ e) const;
|
||||
void LogInputPasted(CalculatorApp::Common::ViewMode mode) const;
|
||||
void LogConverterInputReceived(CalculatorApp::Common::ViewMode mode);
|
||||
void LogNavBarOpened();
|
||||
void LogError(CalculatorApp::Common::ViewMode mode, Platform::String ^ functionName, Platform::String ^ errorString);
|
||||
internal :
|
||||
void LogStandardException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ const std::exception& e);
|
||||
void LogWinRTException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ winrt::hresult_error const& e);
|
||||
void LogPlatformException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ Platform::Exception ^ e);
|
||||
void LogInputPasted(CalculatorApp::Common::ViewMode mode);
|
||||
|
||||
private:
|
||||
// Create an instance of TraceLogger
|
||||
@@ -64,11 +62,11 @@ namespace CalculatorApp
|
||||
// sampling is involved in Microsoft's diagnostic data collection process.
|
||||
// These keywords provide additional input into how frequently an event might be sampled.
|
||||
// The lower the level of the keyword, the higher the possibility that the corresponding event may be sampled.
|
||||
void LogLevel1Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
|
||||
void LogLevel2Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
|
||||
void LogLevel3Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
|
||||
void LogLevel1Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields);
|
||||
void LogLevel2Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields);
|
||||
void LogLevel3Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields);
|
||||
|
||||
std::unique_ptr<TraceActivity> CreateTraceActivity(std::wstring_view activityName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
|
||||
std::unique_ptr<TraceActivity> CreateTraceActivity(std::wstring_view activityName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields);
|
||||
|
||||
winrt::Windows::Foundation::Diagnostics::LoggingChannel g_calculatorProvider;
|
||||
|
||||
@@ -76,7 +74,7 @@ namespace CalculatorApp
|
||||
std::vector<int> windowIdLog;
|
||||
|
||||
GUID sessionGuid;
|
||||
size_t currentWindowCount = 0;
|
||||
uint64 currentWindowCount = 0;
|
||||
|
||||
winrt::Windows::Foundation::Diagnostics::LoggingActivity m_appLaunchActivity;
|
||||
};
|
||||
|
Reference in New Issue
Block a user