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

@ -112,15 +112,10 @@ APPLICATION_INFO::UpdateAppOfflineFileHandle()
// if it was, log that app_offline has been dropped.
if (m_fAppOfflineFound)
{
STACK_STRU(strEventMsg, 256);
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED_MSG)))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED,
strEventMsg.QueryStr());
}
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED_MSG);
}
m_fAppOfflineFound = FALSE;
@ -157,16 +152,11 @@ APPLICATION_INFO::UpdateAppOfflineFileHandle()
// recycle the application
if (m_pApplication != NULL)
{
STACK_STRU(strEventMsg, 256);
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
UTILITY::LogEventF(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_MSG,
m_pApplication->QueryConfig()->QueryApplicationPath()->QueryStr())))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE,
strEventMsg.QueryStr());
}
m_pApplication->QueryConfig()->QueryApplicationPath()->QueryStr());
RecycleApplication();
}
@ -268,32 +258,20 @@ APPLICATION_INFO::FindRequestHandlerAssembly()
{
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,
ASPNETCORE_EVENT_INPROCESS_RH_MISSING,
strEventMsg.QueryStr());
}
goto Finished;
ASPNETCORE_EVENT_INPROCESS_RH_MISSING_MSG);
}
}
else
{
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,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING,
strEventMsg.QueryStr());
}
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING,
ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING_MSG);
goto Finished;
}

View File

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

View File

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

View File

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

View File

@ -627,3 +627,30 @@ UTILITY::LogEvent(
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
);
static
VOID
LogEventF(
_In_ HANDLE hEventLog,
_In_ WORD dwEventInfoType,
_In_ DWORD dwEventId,
__in PCWSTR pstrMsg,
...
);
private:
UTILITY() {}

View File

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

View File

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

View File

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