/** * @param eLogLevel - log level number. * @param eEntryMode - entry mode. * @param rcsConsoleAccess - provides synchronous access to the console. * @param pszEntry - log entry text. * @return true if operation was completed successfully. */ BOOL CTextLogFile::WriteLogEntry(BUGTRAP_LOGLEVEL eLogLevel, ENTRY_MODE eEntryMode, CRITICAL_SECTION& rcsConsoleAccess, PCTSTR pszEntry) { BOOL bResult = TRUE; BUGTRAP_LOGLEVEL eLogFileLevel = GetLogLevel(); if (eLogLevel <= eLogFileLevel) { SYSTEMTIME st; GetLocalTime(&st); if (! WriteLogEntryToConsole(eLogLevel, &st, rcsConsoleAccess, pszEntry)) FillEntryText(eLogLevel, &st, pszEntry); EncodeEntryText(); switch (eEntryMode) { case EM_APPEND: AddToTail(FALSE); break; case EM_INSERT: AddToHead(FALSE); break; default: _ASSERT(FALSE); bResult = FALSE; } } return bResult; }
/** * @param eLogLevel - log level number. * @param eEntryMode - entry mode. * @param rcsConsoleAccess - provides synchronous access to the console. * @param pszEntry - log entry text. * @return true if operation was completed successfully. */ BOOL CLogStream::WriteLogEntry(BUGTRAP_LOGLEVEL eLogLevel, ENTRY_MODE eEntryMode, CRITICAL_SECTION& rcsConsoleAccess, PCTSTR pszEntry) { _ASSERTE(m_hFile != INVALID_HANDLE_VALUE); if (m_hFile == INVALID_HANDLE_VALUE) return FALSE; _ASSERTE(eEntryMode == EM_APPEND); if (eEntryMode != EM_APPEND) return FALSE; BUGTRAP_LOGLEVEL eLogFileLevel = GetLogLevel(); if (eLogLevel <= eLogFileLevel) { SYSTEMTIME st; GetLocalTime(&st); if (! WriteLogEntryToConsole(eLogLevel, &st, rcsConsoleAccess, pszEntry)) FillEntryText(eLogLevel, &st, pszEntry); EncodeEntryText(); const BYTE* pBuffer = m_MemStream.GetBuffer(); if (pBuffer == NULL) return FALSE; DWORD dwLength = (DWORD)m_MemStream.GetLength(); _ASSERTE(dwLength > 0); DWORD dwWritten; return WriteFile(m_hFile, pBuffer, dwLength, &dwWritten, NULL); } return TRUE; }