Merge pull request #764 from aspnet/pakrym/cleanup-logs

Cleanup LogEvent calls
This commit is contained in:
Pavel Krymets 2018-04-09 15:28:27 -07:00 committed by GitHub
commit 6e54256fca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 240 additions and 342 deletions

View File

@ -111,16 +111,11 @@ APPLICATION_INFO::UpdateAppOfflineFileHandle()
// Check if app offline was originally present. // Check if app offline was originally present.
// if it was, log that app_offline has been dropped. // if it was, log that app_offline has been dropped.
if (m_fAppOfflineFound) if (m_fAppOfflineFound)
{
STACK_STRU(strEventMsg, 256);
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED_MSG)))
{ {
UTILITY::LogEvent(g_hEventLog, UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED, ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED_MSG);
}
} }
m_fAppOfflineFound = FALSE; m_fAppOfflineFound = FALSE;
@ -157,16 +152,11 @@ APPLICATION_INFO::UpdateAppOfflineFileHandle()
// recycle the application // recycle the application
if (m_pApplication != NULL) if (m_pApplication != NULL)
{ {
STACK_STRU(strEventMsg, 256); UTILITY::LogEventF(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_MSG,
m_pApplication->QueryConfig()->QueryApplicationPath()->QueryStr())))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE, ASPNETCORE_EVENT_RECYCLE_APPOFFLINE,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_MSG,
} m_pApplication->QueryConfig()->QueryApplicationPath()->QueryStr());
RecycleApplication(); RecycleApplication();
} }
@ -267,33 +257,21 @@ APPLICATION_INFO::FindRequestHandlerAssembly()
if (m_pConfiguration->QueryHostingModel() == APP_HOSTING_MODEL::HOSTING_IN_PROCESS) if (m_pConfiguration->QueryHostingModel() == APP_HOSTING_MODEL::HOSTING_IN_PROCESS)
{ {
if (FAILED(hr = FindNativeAssemblyFromHostfxr(&struFileName))) if (FAILED(hr = FindNativeAssemblyFromHostfxr(&struFileName)))
{
STACK_STRU(strEventMsg, 256);
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_INPROCESS_RH_MISSING_MSG)))
{ {
UTILITY::LogEvent(g_hEventLog, UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_INPROCESS_RH_MISSING, ASPNETCORE_EVENT_INPROCESS_RH_MISSING,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_INPROCESS_RH_MISSING_MSG);
}
goto Finished;
} }
} }
else else
{ {
if (FAILED(hr = FindNativeAssemblyFromGlobalLocation(&struFileName))) if (FAILED(hr = FindNativeAssemblyFromGlobalLocation(&struFileName)))
{
STACK_STRU(strEventMsg, 256);
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING_MSG)))
{ {
UTILITY::LogEvent(g_hEventLog, UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING, ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING_MSG);
}
goto Finished; goto Finished;
} }

View File

@ -24,7 +24,6 @@ APPLICATION_MANAGER::GetOrCreateApplicationInfo(
BOOL fMixedHostingModelError = FALSE; BOOL fMixedHostingModelError = FALSE;
BOOL fDuplicatedInProcessApp = FALSE; BOOL fDuplicatedInProcessApp = FALSE;
PCWSTR pszApplicationId = NULL; PCWSTR pszApplicationId = NULL;
STACK_STRU ( strEventMsg, 256 );
DBG_ASSERT(pServer); DBG_ASSERT(pServer);
DBG_ASSERT(pConfig); DBG_ASSERT(pConfig);
@ -160,41 +159,29 @@ Finished:
{ {
if (fDuplicatedInProcessApp) if (fDuplicatedInProcessApp)
{ {
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
ASPNETCORE_EVENT_DUPLICATED_INPROCESS_APP_MSG,
pszApplicationId)))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_DUPLICATED_INPROCESS_APP, ASPNETCORE_EVENT_DUPLICATED_INPROCESS_APP,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_DUPLICATED_INPROCESS_APP_MSG,
} pszApplicationId);
} }
else if (fMixedHostingModelError) else if (fMixedHostingModelError)
{ {
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
ASPNETCORE_EVENT_MIXED_HOSTING_MODEL_ERROR_MSG,
pszApplicationId,
pConfig->QueryHostingModel())))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_MIXED_HOSTING_MODEL_ERROR, ASPNETCORE_EVENT_MIXED_HOSTING_MODEL_ERROR,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_MIXED_HOSTING_MODEL_ERROR_MSG,
} pszApplicationId,
pConfig->QueryHostingModel());
} }
else else
{ {
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
ASPNETCORE_EVENT_ADD_APPLICATION_ERROR_MSG,
pszApplicationId,
hr)))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_ADD_APPLICATION_ERROR, ASPNETCORE_EVENT_ADD_APPLICATION_ERROR,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_ADD_APPLICATION_ERROR_MSG,
} pszApplicationId,
hr);
} }
} }
@ -349,16 +336,11 @@ APPLICATION_MANAGER::RecycleApplicationFromManager(
APPLICATION_INFO* pRecord; APPLICATION_INFO* pRecord;
// Application got recycled. Log an event // Application got recycled. Log an event
STACK_STRU(strEventMsg, 256); UTILITY::LogEventF(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_RECYCLE_CONFIGURATION_MSG,
path)))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_CONFIGURATION, ASPNETCORE_EVENT_RECYCLE_CONFIGURATION,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_RECYCLE_CONFIGURATION_MSG,
} path);
hr = key.Initialize(path); hr = key.Initialize(path);
if (FAILED(hr)) if (FAILED(hr))
@ -386,16 +368,11 @@ Finished:
if (FAILED(hr)) if (FAILED(hr))
{ {
// Failed to recycle an application. Log an event // Failed to recycle an application. Log an event
STACK_STRU(strEventMsg, 256); UTILITY::LogEventF(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_RECYCLE_FAILURE_CONFIGURATION_MSG,
pszApplicationId)))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_RECYCLE_APP_FAILURE, ASPNETCORE_EVENT_RECYCLE_APP_FAILURE,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_RECYCLE_FAILURE_CONFIGURATION_MSG,
} pszApplicationId);
// Need to recycle the process as we cannot recycle the application // Need to recycle the process as we cannot recycle the application
if (!g_fRecycleProcessCalled) if (!g_fRecycleProcessCalled)
{ {

View File

@ -159,17 +159,11 @@ HRESULT
} }
if (fDisableANCM) if (fDisableANCM)
{
// Logging
STACK_STRU(strEventMsg, 256);
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_MODULE_DISABLED_MSG)))
{ {
UTILITY::LogEvent(g_hEventLog, UTILITY::LogEvent(g_hEventLog,
EVENTLOG_WARNING_TYPE, EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_MODULE_DISABLED, ASPNETCORE_EVENT_MODULE_DISABLED,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_MODULE_DISABLED_MSG);
}
// this will return 500 error to client // this will return 500 error to client
// as we did not register the module // as we did not register the module
goto Finished; goto Finished;

View File

@ -39,7 +39,6 @@ HOSTFXR_UTILITY::GetStandaloneHostfxrParameters(
STRU struArguments; STRU struArguments;
STRU struHostFxrPath; STRU struHostFxrPath;
STRU struRuntimeConfigLocation; STRU struRuntimeConfigLocation;
STRU strEventMsg;
DWORD dwPosition; DWORD dwPosition;
// Obtain the app name from the processPath section. // Obtain the app name from the processPath section.
@ -80,31 +79,23 @@ HOSTFXR_UTILITY::GetStandaloneHostfxrParameters(
{ {
hr = E_APPLICATION_ACTIVATION_EXEC_FAILURE; hr = E_APPLICATION_ACTIVATION_EXEC_FAILURE;
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(hEventLog,
ASPNETCORE_EVENT_INPROCESS_FULL_FRAMEWORK_APP_MSG,
pcwzApplicationPhysicalPath,
hr)))
{
UTILITY::LogEvent( hEventLog,
EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_FULL_FRAMEWORK_APP, ASPNETCORE_EVENT_INPROCESS_FULL_FRAMEWORK_APP,
strEventMsg.QueryStr() ); ASPNETCORE_EVENT_INPROCESS_FULL_FRAMEWORK_APP_MSG,
} pcwzApplicationPhysicalPath,
hr);
} }
else else
{ {
// If a runtime config file does exist, report a file not found on the app.exe // If a runtime config file does exist, report a file not found on the app.exe
hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(hEventLog,
ASPNETCORE_EVENT_APPLICATION_EXE_NOT_FOUND_MSG,
pcwzApplicationPhysicalPath,
hr)))
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_APPLICATION_EXE_NOT_FOUND, ASPNETCORE_EVENT_APPLICATION_EXE_NOT_FOUND,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_APPLICATION_EXE_NOT_FOUND_MSG,
} pcwzApplicationPhysicalPath,
hr);
} }
goto Finished; goto Finished;
@ -249,16 +240,12 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
// then it is an invalid argument. // then it is an invalid argument.
// //
hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);; hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);;
if (SUCCEEDED(struEventMsg.SafeSnwprintf( UTILITY::LogEventF(hEventLog,
ASPNETCORE_EVENT_INVALID_PROCESS_PATH_MSG,
struExpandedProcessPath.QueryStr(),
hr)))
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_GENERAL_ERROR_MSG, ASPNETCORE_EVENT_GENERAL_ERROR_MSG,
struEventMsg.QueryStr()); ASPNETCORE_EVENT_INVALID_PROCESS_PATH_MSG,
} struExpandedProcessPath.QueryStr(),
hr);
} }
} }
@ -473,16 +460,13 @@ HOSTFXR_UTILITY::GetAbsolutePathToHostFxr(
if (!UTILITY::DirectoryExists(&struHostFxrPath)) if (!UTILITY::DirectoryExists(&struHostFxrPath))
{ {
hr = ERROR_BAD_ENVIRONMENT; hr = ERROR_BAD_ENVIRONMENT;
if (SUCCEEDED(struEventMsg.SafeSnwprintf( UTILITY::LogEventF(hEventLog,
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND_MSG,
struHostFxrPath.QueryStr(),
hr)))
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND, ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND,
struEventMsg.QueryStr()); struEventMsg.QueryStr(),
} ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND_MSG,
struHostFxrPath.QueryStr(),
hr);
goto Finished; goto Finished;
} }
@ -505,16 +489,12 @@ HOSTFXR_UTILITY::GetAbsolutePathToHostFxr(
if (vVersionFolders.size() == 0) if (vVersionFolders.size() == 0)
{ {
hr = HRESULT_FROM_WIN32(ERROR_BAD_ENVIRONMENT); hr = HRESULT_FROM_WIN32(ERROR_BAD_ENVIRONMENT);
if (SUCCEEDED(struEventMsg.SafeSnwprintf( UTILITY::LogEventF(hEventLog,
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND_MSG,
struHostFxrPath.QueryStr(),
hr)))
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND, ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND,
struEventMsg.QueryStr()); ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND_MSG,
} struHostFxrPath.QueryStr(),
hr);
goto Finished; goto Finished;
} }
@ -535,16 +515,12 @@ HOSTFXR_UTILITY::GetAbsolutePathToHostFxr(
{ {
// ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND_MSG // ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND_MSG
hr = HRESULT_FROM_WIN32(ERROR_FILE_INVALID); hr = HRESULT_FROM_WIN32(ERROR_FILE_INVALID);
if (SUCCEEDED(struEventMsg.SafeSnwprintf( UTILITY::LogEventF(hEventLog,
ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND_MSG,
struHostFxrPath.QueryStr(),
hr)))
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND, ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND,
struEventMsg.QueryStr()); ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND_MSG,
} struHostFxrPath.QueryStr(),
hr);
goto Finished; goto Finished;
} }

View File

@ -627,3 +627,30 @@ UTILITY::LogEvent(
fwprintf(stderr, L"ERROR: %s\n", pstrMsg); fwprintf(stderr, L"ERROR: %s\n", pstrMsg);
} }
} }
VOID
UTILITY::LogEventF(
_In_ HANDLE hEventLog,
_In_ WORD dwEventInfoType,
_In_ DWORD dwEventId,
_In_ LPCWSTR pstrMsg,
...
)
{
va_list argsList;
va_start(argsList, pstrMsg);
STACK_STRU ( strEventMsg, 256 );
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
pstrMsg,
argsList)))
{
UTILITY::LogEvent(hEventLog,
dwEventInfoType,
dwEventId,
strEventMsg.QueryStr());
}
va_end( argsList );
}

View File

@ -120,6 +120,16 @@ public:
_In_ LPCWSTR pstrMsg _In_ LPCWSTR pstrMsg
); );
static
VOID
LogEventF(
_In_ HANDLE hEventLog,
_In_ WORD dwEventInfoType,
_In_ DWORD dwEventId,
__in PCWSTR pstrMsg,
...
);
private: private:
UTILITY() {} UTILITY() {}

View File

@ -103,17 +103,11 @@ Finished:
if (FAILED(hr)) if (FAILED(hr))
{ {
STACK_STRU(strEventMsg, 256); UTILITY::LogEventF(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_APP_SHUTDOWN_FAILURE_MSG,
m_pConfig->QueryConfigPath()->QueryStr())))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_WARNING_TYPE, EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE, ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_APP_SHUTDOWN_FAILURE_MSG,
} m_pConfig->QueryConfigPath()->QueryStr());
// //
// Managed layer may block the shutdown and lead to shutdown timeout // Managed layer may block the shutdown and lead to shutdown timeout
@ -565,17 +559,12 @@ Finished:
} }
if (FAILED(hr) && m_pConfig->QueryStdoutLogEnabled()) if (FAILED(hr) && m_pConfig->QueryStdoutLogEnabled())
{ {
STRU strEventMsg; UTILITY::LogEventF(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_INVALID_STDOUT_LOG_FILE_MSG,
m_struLogFilePath.QueryStr(),
hr)))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_WARNING_TYPE, EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_CONFIG_ERROR, ASPNETCORE_EVENT_CONFIG_ERROR,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_INVALID_STDOUT_LOG_FILE_MSG,
} m_struLogFilePath.QueryStr(),
hr);
} }
} }
@ -767,20 +756,15 @@ Finished:
if (FAILED(hr)) if (FAILED(hr))
{ {
STACK_STRU(strEventMsg, 256);
m_status = APPLICATION_STATUS::FAIL; m_status = APPLICATION_STATUS::FAIL;
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_LOAD_CLR_FALIURE,
ASPNETCORE_EVENT_LOAD_CLR_FALIURE_MSG, ASPNETCORE_EVENT_LOAD_CLR_FALIURE_MSG,
m_pConfig->QueryApplicationPath()->QueryStr(), m_pConfig->QueryApplicationPath()->QueryStr(),
m_pConfig->QueryApplicationPhysicalPath()->QueryStr(), m_pConfig->QueryApplicationPhysicalPath()->QueryStr(),
hr))) hr);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_LOAD_CLR_FALIURE,
strEventMsg.QueryStr());
}
} }
if (fLocked) if (fLocked)
@ -926,7 +910,6 @@ IN_PROCESS_APPLICATION::LogErrorsOnMainExit(
DWORD dwNumBytesRead; DWORD dwNumBytesRead;
STRU struStdErrLog; STRU struStdErrLog;
LARGE_INTEGER li = { 0 }; LARGE_INTEGER li = { 0 };
STRU strEventMsg;
BOOL fLogged = FALSE; BOOL fLogged = FALSE;
DWORD dwFilePointer = 0; DWORD dwFilePointer = 0;
@ -949,18 +932,16 @@ IN_PROCESS_APPLICATION::LogErrorsOnMainExit(
{ {
if (ReadFile(m_hLogFileHandle, pzFileContents, 4096, &dwNumBytesRead, NULL)) if (ReadFile(m_hLogFileHandle, pzFileContents, 4096, &dwNumBytesRead, NULL))
{ {
if (SUCCEEDED(struStdErrLog.CopyA(m_pzFileContents, m_dwStdErrReadTotal)) && if (SUCCEEDED(struStdErrLog.CopyA(m_pzFileContents, m_dwStdErrReadTotal)))
SUCCEEDED(strEventMsg.SafeSnwprintf( {
UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_STDOUT_MSG, ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_STDOUT_MSG,
m_pConfig->QueryApplicationPath()->QueryStr(), m_pConfig->QueryApplicationPath()->QueryStr(),
m_pConfig->QueryApplicationPhysicalPath()->QueryStr(), m_pConfig->QueryApplicationPhysicalPath()->QueryStr(),
hr, hr,
struStdErrLog.QueryStr()))) struStdErrLog.QueryStr());
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT,
strEventMsg.QueryStr());
fLogged = TRUE; fLogged = TRUE;
} }
@ -973,18 +954,16 @@ IN_PROCESS_APPLICATION::LogErrorsOnMainExit(
{ {
if (m_dwStdErrReadTotal > 0) if (m_dwStdErrReadTotal > 0)
{ {
if (SUCCEEDED(struStdErrLog.CopyA(m_pzFileContents, m_dwStdErrReadTotal)) && if (SUCCEEDED(struStdErrLog.CopyA(m_pzFileContents, m_dwStdErrReadTotal)))
SUCCEEDED(strEventMsg.SafeSnwprintf( {
UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_STDERR_MSG, ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_STDERR_MSG,
m_pConfig->QueryApplicationPath()->QueryStr(), m_pConfig->QueryApplicationPath()->QueryStr(),
m_pConfig->QueryApplicationPhysicalPath()->QueryStr(), m_pConfig->QueryApplicationPhysicalPath()->QueryStr(),
hr, hr,
struStdErrLog.QueryStr()))) struStdErrLog.QueryStr());
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT,
strEventMsg.QueryStr());
fLogged = TRUE; fLogged = TRUE;
} }
} }
@ -993,19 +972,15 @@ IN_PROCESS_APPLICATION::LogErrorsOnMainExit(
if (!fLogged) if (!fLogged)
{ {
// If we didn't log, log the generic message. // If we didn't log, log the generic message.
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_MSG, ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_MSG,
m_pConfig->QueryApplicationPath()->QueryStr(), m_pConfig->QueryApplicationPath()->QueryStr(),
m_pConfig->QueryApplicationPhysicalPath()->QueryStr(), m_pConfig->QueryApplicationPhysicalPath()->QueryStr(),
hr))) hr);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT,
strEventMsg.QueryStr());
fLogged = TRUE; fLogged = TRUE;
} }
}
} }
// //

View File

@ -110,7 +110,6 @@ PROCESS_MANAGER::GetProcess(
HRESULT hr = S_OK; HRESULT hr = S_OK;
BOOL fSharedLock = FALSE; BOOL fSharedLock = FALSE;
BOOL fExclusiveLock = FALSE; BOOL fExclusiveLock = FALSE;
STACK_STRU(strEventMsg, 256);
DWORD dwProcessIndex = 0; DWORD dwProcessIndex = 0;
SERVER_PROCESS *pSelectedServerProcess = NULL; SERVER_PROCESS *pSelectedServerProcess = NULL;
@ -189,15 +188,11 @@ PROCESS_MANAGER::GetProcess(
// //
// rapid fails per minute exceeded, do not create new process. // rapid fails per minute exceeded, do not create new process.
// //
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
ASPNETCORE_EVENT_RAPID_FAIL_COUNT_EXCEEDED_MSG,
pConfig->QueryRapidFailsPerMinute())))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RAPID_FAIL_COUNT_EXCEEDED, ASPNETCORE_EVENT_RAPID_FAIL_COUNT_EXCEEDED,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_RAPID_FAIL_COUNT_EXCEEDED_MSG,
} pConfig->QueryRapidFailsPerMinute());
hr = HRESULT_FROM_WIN32(ERROR_SERVER_DISABLED); hr = HRESULT_FROM_WIN32(ERROR_SERVER_DISABLED);
goto Finished; goto Finished;

View File

@ -144,7 +144,6 @@ SERVER_PROCESS::SetupListenPort(
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
ENVIRONMENT_VAR_ENTRY *pEntry = NULL; ENVIRONMENT_VAR_ENTRY *pEntry = NULL;
STACK_STRU(strEventMsg, 256);
*pfCriticalError = FALSE; *pfCriticalError = FALSE;
pEnvironmentVarTable->FindKey(ASPNETCORE_PORT_ENV_STR, &pEntry); pEnvironmentVarTable->FindKey(ASPNETCORE_PORT_ENV_STR, &pEntry);
@ -209,20 +208,16 @@ Finished:
if (FAILED(hr)) if (FAILED(hr))
{ {
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_PROCESS_START_SUCCESS,
ASPNETCORE_EVENT_PROCESS_START_PORTSETUP_ERROR_MSG, ASPNETCORE_EVENT_PROCESS_START_PORTSETUP_ERROR_MSG,
m_struAppFullPath.QueryStr(), m_struAppFullPath.QueryStr(),
m_struPhysicalPath.QueryStr(), m_struPhysicalPath.QueryStr(),
m_dwPort, m_dwPort,
MIN_PORT, MIN_PORT,
MAX_PORT, MAX_PORT,
hr))) hr);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_PROCESS_START_SUCCESS,
strEventMsg.QueryStr());
}
} }
return hr; return hr;
@ -744,7 +739,6 @@ SERVER_PROCESS::StartProcess(
STARTUPINFOW startupInfo = {0}; STARTUPINFOW startupInfo = {0};
DWORD dwRetryCount = 2; // should we allow customer to config it DWORD dwRetryCount = 2; // should we allow customer to config it
DWORD dwCreationFlags = 0; DWORD dwCreationFlags = 0;
STACK_STRU( strEventMsg, 256);
MULTISZ mszNewEnvironment; MULTISZ mszNewEnvironment;
ENVIRONMENT_VAR_HASH *pHashTable = NULL; ENVIRONMENT_VAR_HASH *pHashTable = NULL;
PWSTR pStrStage = NULL; PWSTR pStrStage = NULL;
@ -890,17 +884,13 @@ SERVER_PROCESS::StartProcess(
// Backend process starts successfully. Set retry counter to 0 // Backend process starts successfully. Set retry counter to 0
dwRetryCount = 0; dwRetryCount = 0;
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_PROCESS_START_SUCCESS,
ASPNETCORE_EVENT_PROCESS_START_SUCCESS_MSG, ASPNETCORE_EVENT_PROCESS_START_SUCCESS_MSG,
m_struAppFullPath.QueryStr(), m_struAppFullPath.QueryStr(),
m_dwProcessId, m_dwProcessId,
m_dwPort))) m_dwPort);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_PROCESS_START_SUCCESS,
strEventMsg.QueryStr());
}
goto Finished; goto Finished;
@ -911,7 +901,9 @@ SERVER_PROCESS::StartProcess(
dwRetryCount = 0; dwRetryCount = 0;
} }
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_PROCESS_START_ERROR,
ASPNETCORE_EVENT_PROCESS_START_ERROR_MSG, ASPNETCORE_EVENT_PROCESS_START_ERROR_MSG,
m_struAppFullPath.QueryStr(), m_struAppFullPath.QueryStr(),
m_struPhysicalPath.QueryStr(), m_struPhysicalPath.QueryStr(),
@ -919,13 +911,7 @@ SERVER_PROCESS::StartProcess(
pStrStage, pStrStage,
hr, hr,
m_dwPort, m_dwPort,
dwRetryCount))) dwRetryCount);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_PROCESS_START_ERROR,
strEventMsg.QueryStr());
}
if (processInformation.hThread != NULL) if (processInformation.hThread != NULL)
{ {
@ -960,18 +946,14 @@ Finished:
m_Timer.CancelTimer(); m_Timer.CancelTimer();
} }
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_PROCESS_START_FAILURE,
ASPNETCORE_EVENT_PROCESS_START_FAILURE_MSG, ASPNETCORE_EVENT_PROCESS_START_FAILURE_MSG,
m_struAppFullPath.QueryStr(), m_struAppFullPath.QueryStr(),
m_struPhysicalPath.QueryStr(), m_struPhysicalPath.QueryStr(),
m_struCommandLine.QueryStr(), m_struCommandLine.QueryStr(),
m_dwPort))) m_dwPort);
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_PROCESS_START_FAILURE,
strEventMsg.QueryStr());
}
} }
return hr; return hr;
} }
@ -1101,17 +1083,12 @@ Finished:
if (m_fStdoutLogEnabled) if (m_fStdoutLogEnabled)
{ {
// Log the error // Log the error
STRU strEventMsg; UTILITY::LogEventF(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_INVALID_STDOUT_LOG_FILE_MSG,
m_struFullLogFile.IsEmpty()? m_struLogFile.QueryStr() : m_struFullLogFile.QueryStr(),
hr)))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_WARNING_TYPE, EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_CONFIG_ERROR, ASPNETCORE_EVENT_CONFIG_ERROR,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_INVALID_STDOUT_LOG_FILE_MSG,
} m_struFullLogFile.IsEmpty()? m_struLogFile.QueryStr() : m_struFullLogFile.QueryStr(),
hr);
} }
// The log file was not created yet in case of failure. No need to clean it // The log file was not created yet in case of failure. No need to clean it
m_struFullLogFile.Reset(); m_struFullLogFile.Reset();
@ -1917,7 +1894,6 @@ SERVER_PROCESS::SendShutdownHttpMessage( VOID )
STRU strUrl; STRU strUrl;
DWORD dwStatusCode = 0; DWORD dwStatusCode = 0;
DWORD dwSize = sizeof(dwStatusCode); DWORD dwSize = sizeof(dwStatusCode);
STACK_STRU(strEventMsg, 256);
hSession = WinHttpOpen(L"", hSession = WinHttpOpen(L"",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
@ -2020,16 +1996,12 @@ SERVER_PROCESS::SendShutdownHttpMessage( VOID )
} }
// log // log
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
ASPNETCORE_EVENT_SENT_SHUTDOWN_HTTP_REQUEST_MSG,
m_dwProcessId,
dwStatusCode)))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_SENT_SHUTDOWN_HTTP_REQUEST, ASPNETCORE_EVENT_SENT_SHUTDOWN_HTTP_REQUEST,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_SENT_SHUTDOWN_HTTP_REQUEST_MSG,
} m_dwProcessId,
dwStatusCode);
Finished: Finished:
if (hRequest) if (hRequest)
@ -2120,8 +2092,6 @@ SERVER_PROCESS::TerminateBackendProcess(
VOID VOID
) )
{ {
STACK_STRU(strEventMsg, 256);
if (InterlockedCompareExchange(&m_lStopping, 1L, 0L) == 0L) if (InterlockedCompareExchange(&m_lStopping, 1L, 0L) == 0L)
{ {
// backend process will be terminated, remove the waitcallback // backend process will be terminated, remove the waitcallback
@ -2144,14 +2114,10 @@ SERVER_PROCESS::TerminateBackendProcess(
} }
// log a warning for ungraceful shutdown // log a warning for ungraceful shutdown
if (SUCCEEDED(strEventMsg.SafeSnwprintf( UTILITY::LogEventF(g_hEventLog,
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE_MSG,
m_dwProcessId)))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_WARNING_TYPE, EVENTLOG_WARNING_TYPE,
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE, ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE_MSG,
} m_dwProcessId);
} }
} }