📄 herrlogger.cpp
字号:
// HErrLogger.cpp: implementation of the CHErrLogger class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "HErrLogger.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CString CHErrLogger::m_path=_T("errors.log");
extern CString g_path;
CHErrLogger::CHErrLogger()
{
//_path = ;
m_path = g_path + m_path;
}
CHErrLogger::~CHErrLogger()
{
}
BOOL CHErrLogger::LogError(CString err)
{
CStdioFile File;
CFileException ex;
if (m_path == "") m_path=_T("errors.log");
if (!File.Open(m_path, CFile::modeWrite | CFile::modeCreate|
CFile::modeNoTruncate | CFile::typeText, 0)) {
ex.ReportError();
return FALSE;
} ;
TRY {
File.SeekToEnd();
File.WriteString(err);
File.Close();
} CATCH (CFileException, e) {
//AfxMessageBox(_T("Unable to save error."));
return FALSE;
} END_CATCH
return TRUE;
}
BOOL CHErrLogger::LogError(UINT errCode)
{
CStdioFile File;
CFileException ex;
static CString sErr;
// CString sz;
// sz.Format(_T("Err: [code:%d], [date:%s], [time:%s], [reason:%s]\n"),e.code,e.date,e.time,e.result);
if (m_path == "") m_path=_T("errors.log");
if (!File.Open(m_path, CFile::modeWrite | CFile::modeCreate|
CFile::modeNoTruncate | CFile::typeText, 0)) {
ex.ReportError();
return FALSE;
} ;
TRY {
sErr = GetErrorString(errCode);
File.SeekToEnd();
File.WriteString(sErr);
File.Close();
} CATCH (CFileException, e) {
return FALSE;
} END_CATCH
return TRUE;
}
void CHErrLogger::SetFilePath(CString path)
{
m_path = path;
}
BOOL CHErrLogger::LogError(CTapiObj::TEx e)
{
CStdioFile File;
CFileException ex;
static CString sErr;
// CString sz;
sErr.Format(_T("Err: [code:%d], [date:%s], [time:%s], [reason:%s]\n"),e.code,e.date,e.time,GetErrorString(e.code)+_T(" ")+e.result);
if (m_path == "") m_path=_T("errors.log");
if (!File.Open(m_path, CFile::modeWrite | CFile::modeCreate|
CFile::modeNoTruncate | CFile::typeText, 0)) {
ex.ReportError();
return FALSE;
} ;
TRY {
File.SeekToEnd();
File.WriteString(sErr);
File.Close();
} CATCH (CFileException, e) {
return FALSE;
} END_CATCH
return TRUE;
}
CString CHErrLogger::GetErrorString(long TapiErrCode)
{
switch (TapiErrCode) {
case LINEERR_ADDRESSBLOCKED :
return _T("The specified address is blocked from being dialed on the specified call.");
case LINEERR_ALLOCATED :
return _T("The line cannot be opened due to a persistent condition, such as that of a serial port being exclusively opened by another process.");
case LINEERR_BADDEVICEID :
return _T("The specified device identifier or line device identifier (such as in a dwDeviceID parameter) is invalid or out of range.");
case LINEERR_BEARERMODEUNAVAIL :
return _T("The bearer mode member in LINECALLPARAMS is invalid, the bearer mode specified in LINECALLPARAMS is not available, or the call's bearer mode cannot be changed to the specified bearer mode.");
case LINEERR_BILLINGREJECTED :
return _T("The billing mode of the call was rejected.");
case LINEERR_CALLUNAVAIL :
return _T("All call appearances on the specified address are currently in use.");
case LINEERR_COMPLETIONOVERRUN :
return _T("The maximum number of outstanding call completions has been exceeded. ");
case LINEERR_CONFERENCEFULL :
return _T("The maximum number of parties for a conference has been reached, or the requested number of parties cannot be satisfied.");
case LINEERR_DIALBILLING :
return _T("The dialable address parameter contains dialing control characters that are not processed by the service provider.");
case LINEERR_DIALDIALTONE :
return _T("The dialable address parameter contains dialing control characters that are not processed by the service provider. ");
case LINEERR_DIALPROMPT :
return _T("The dialable address parameter contains dialing control characters that are not processed by the service provider.");
case LINEERR_DIALQUIET :
return _T("The dialable address parameter contains dialing control characters that are not processed by the service provider.");
case LINEERR_DIALVOICEDETECT :
return _T("Use of the \":\" dial modifier is not supported. This value is exposed only to applications that negotiate a TAPI version of 2.0 or higher.");
// case LINEERR_DISCONNECTED : LoadStrin
//return _T("");
case LINEERR_INCOMPATIBLEAPIVERSION :
return _T("The application requested a TAPI version or version range that is either incompatible with, or cannot be supported by, the Telephony API implementation and the corresponding service provider. ");
// case LINEERR_INCOMPATIBLEEXTVERSION :
// return _T("");
case LINEERR_INIFILECORRUPT :
return _T("The Telephon.ini file cannot be read or understood properly by TAPI because of internal inconsistencies or formatting problems. For example, the [Locations], [Cards], or [Countries] section of the Telephon.ini file may be corrupted or inconsistent.");
case LINEERR_INUSE :
return _T("The line device is in use and cannot currently be configured, allow a party to be added, allow a call to be answered, allow a call to be placed, or allow a call to be transferred.");
case LINEERR_INVALADDRESS :
return _T("A specified address is either invalid or not allowed. If invalid, the address contains invalid characters or digits, or the destination address contains dialing control characters (W, @, $, or ?) that are not supported by the service provider. If not allowed, the specified address is either not assigned to the specified line or is not valid for address redirection.");
case LINEERR_INVALADDRESSID :
return _T("The specified address identifier is either invalid or out of range.");
case LINEERR_INVALADDRESSMODE :
return _T("The specified address mode is invalid.");
case LINEERR_INVALADDRESSSTATE :
return _T("The specified address state contains one or more bits that are not LINEADDRESSSTATE_ constants.");
// case LINEERR_INVALADDRESSTYPE : LoadString(AfxGetApp()->m_hInstance,IDS_LINEERR_INVALADDRESSTYPE ,res.GetBuffer(nLength),nSize); break;
// case LINEERR_INVALAGENTACTIVITY : LoadString(AfxGetApp()->m_hInstance,IDS_ ,res.GetBuffer(nLength),nSize); break;
case LINEERR_INVALAGENTACTIVITY :
return _T("The specified agent activity is not valid.\nThe application invoking this operation is the target of the indirect handoff. That is, TAPI has determined that the calling application is also the highest priority application for the given media type. This value is exposed only to applications that negotiate a TAPI version of 2.0 or higher. \n");
case LINEERR_INVALAGENTGROUP :
return _T("The specified agent group information is not valid or contains errors. The requested action has not been carried out. \nLINEERR_INVALAGENTGROUP \nThe application referenced an agent group that is not valid. This value is exposed only to applications that negotiate a TAPI version of 2.0 or higher.");
// case LINEERR_INVALAGENTGROUP : LoadString(AfxGetApp()->m_hInstance,IDS_ ,res.GetBuffer(nLength),nSize); break;
case LINEERR_INVALAGENTID :
return _T("LINEERR_INVALAGENTID \nThe specified agent identifier is invalid. \nLINEERR_INVALAGENTID \nAn invalid agent identifier was used. This value is exposed only to applications that negotiate a TAPI version of 2.0 or higher. \n");
// case LINEERR_INVALAGENTID : LoadString(AfxGetApp()->m_hInstance,IDS_ ,res.GetBuffer(nLength),nSize); break;
// case LINEERR_INVALAGENTSESSIONSTATE : LoadString(AfxGetApp()->m_hInstance,IDS_LINEERR_INVALAGENTSESSIONSTATE ,res.GetBuffer(nLength),nSize); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -