log.h
#pragma once
#include "stdafx.h"
#include class clog
; clog ();
~clog ();
bool open(lpctstr pszfilename);
void close(); // 關閉日誌記錄
void write(int nloglevel, lpctstr pszformat, ...); // 格式化寫入日誌資訊
private:
file* m_out;
};
log.cpp
#include "stdafx.h"
#include "log.h"
#include #include #include #include #pragma warning(disable:4996)
#ifdef _unicode
typedef wchar_t char_t;
typedef std::wstring string_t;
typedef std::wstringstream stringstream_t;
#else
typedef char char_t;
typedef std::string string_t;
typedef std::stringstream stringstream_t;
#endif
// 格式化獲取當前日期
static string_t gettimestr(lpctstr format)
// 獲取作業系統版本資訊
static string_t getosname()
; zeromemory(&info, sizeof(info));
getsysteminfo(&info);
osversioninfoex os;
os.dwosversioninfosize = sizeof(osversioninfoex);
if (::getversionex((osversioninfo*) & os))
break;
case 5:
// 再比較dwminorversion的值
switch (os.dwminorversion)
break;
case 6:
switch (os.dwminorversion)
break;
default:
vname=_t("未知作業系統");
} word nspver = os.wservicepackmajor;
char_t strspver[10];
_itow_s(nspver, strspver, 10, 10);
return vname;
} else
return _t("");
}// 獲取作業系統位數
static string_t getosbit()
else }
// 獲取ie瀏覽器版本
static string_t getiever()
catch (char_t* ex)
return string_t(strver);
}// 獲取磁碟分割槽資訊
static string_t getdisksstr()
count++;
} return strdriv;
}// 獲取記憶體大小
static string_t getmemsize()
// 獲取cpu資訊
static string_t getcpuinfo()
else
else
}return strcpu;
}// 獲取當前執行緒所在路徑
static string_t getprocpath()
// 獲取磁碟使用情況
static string_t getdisksfreespace()
; _tcscpy(buff, strdisks.c_str());
std::queue drivs;
int index = 0;
while (buff[index])
; driv[0] = buff[index];
driv[1] = buff[++index];
index += 3;
drivs.push(driv);
} while (!drivs.empty())
return diskinfo;}//
// clog 日誌記錄類
// 建構函式
clog::clog():m_out(null) {}
bool clog::open(lpctstr pszfilename)
} catch (lpctstr /*ex*/)
return true;
}// 格式化寫入日誌資訊 loglevel: 日誌級別
void clog::write(int loglevel, lpctstr format, ...)
; va_start(ap, format);
_vstprintf(args, format, ap);
string_t strlevel;
switch (loglevel)
if (-1 == _ftprintf(m_out,_t("[%s] [%s] %s\n"),
logtime.c_str(), strlevel.c_str(), args))
throw l"寫入日誌出錯!";
va_end(ap);
} catch (char_t* ex) }
// 關閉記錄檔案
void clog::close()
}clog::~clog()
C 獲取常用硬體資訊
獲取硬碟序列號 public static string getdiskserialnum return result 取得網絡卡的mac位址 public static ilistgetnetcardmacaddress return str 獲取本機ipv4位址 public static st...
c 獲取硬體資訊
using system using system.runtime.interopservices using system.management namespace hardware 取cpu編號 public string getcpuid return strcpuid catch end m...
c 獲取硬體資訊
using system using system.runtime.interopservices using system.management namespace hardware 取cpu編號 public string getcpuid return strcpuid catch end m...