30 sprintf_s(timemsg, 999,
"%i-%02i-%02i %02i:%02i:%02i.%03i\t", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
36 strcat_s(timemsg, 999,
"Warning: ");
39 strcat_s(timemsg, 999,
"FATAL: ");
42 strcat_s(timemsg, 999,
"ERROR: ");
45 strcat_s(timemsg, 999, msg);
48 char errorcodemsg[99];
49 sprintf_s(errorcodemsg, 99,
" (0x%x)", errorCode);
50 strcat_s(timemsg, 999, errorcodemsg);
52 strcat_s(timemsg, 999,
"\n");
54 _write(
logfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
61 if (level > Level::Info)
63 HANDLE h_event_log = RegisterEventSourceA(
nullptr,
"Avionics");
66 DXUT_ERR_MSGBOX(L
"Failed to open event source!", GetLastError());
75 eventType = EVENTLOG_ERROR_TYPE;
78 eventType = EVENTLOG_WARNING_TYPE;
81 eventType = EVENTLOG_INFORMATION_TYPE;
85 if (!ReportEventA(h_event_log, eventType, 0, 0,
nullptr, 1, 0, &msg,
nullptr))
87 DXUT_ERR_MSGBOX(L
"Failed to report event!", GetLastError());
90 DeregisterEventSource(h_event_log);
100 sprintf_s(fileName, 99,
"%i-%02i-%02i.log", st.wYear, st.wMonth, st.wDay);
101 _sopen_s(&
logfile, fileName, _O_RDWR | _O_CREAT | _O_TEXT | _O_APPEND | _O_SEQUENTIAL, SH_DENYWR, S_IWRITE);
104 DXUT_ERR_MSGBOX(L
"Could not open logfile for writing!", errno);
108 sprintf_s(msg, 99,
"Logger::ctor Opened logfile \"%s\"", fileName);
114 Log(
"Logger::dtor Closing logfile...");
void Log(const char *msg, Level level=Info, int errorCode=0)
These have to be in this order.