#include <stdio.h>
#include<windows.h>
#include <time.h>
#define Line __LINE__
#define File __FILE__
void WriteLog(const char *file, int line, char * msg)
{
SYSTEMTIME st;
GetLocalTime(&st);
FILE *fp;
fp=fopen("D:\\log.txt","at");
fprintf(fp,"MyLogInfo: %d-%d-%d %d:%d:%d %s:%d: % s\n",st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond, file,line, msg);
printf(" %d-%d-%d %d:%d:%d %s:%d: %s\n",st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond, file,line, msg);
fclose(fp);
// OutputDebugStringA(msg);
}
int main(int , char**)
{
WriteLog(File,Line, " now error....");
return 0;
}
要保持文件大小不变,可以考虑用临时文件的方法。。。