|
-
August 8th, 2010, 05:49 PM
#1
Ways to insert unique ID into a logging function
I'm writing a logging function for my service app and I need some way to come up with a unique ID to use in it. Here's what I mean. Say, I wrote a function:
Code:
void ReportIntoLog(UINT nUniqueID)
{
//INFO: This is not my actual function. I'm giving it here to show the concept
CString s;
s.Format(_T("Time: %s, Error ID: %d"),
COleDateTime::GetCurrentTime().Format().GetString(),
nUniqueID);
RawWriteIntoLogFile(s);
}
And then, say if I have a situation I'd like to report in the log:
Code:
MY_BIG_ARRAY* pArray = new(std::nothrow) MY_BIG_ARRAY;
if(Array)
{
//Work with array
}
else
{
ReportIntoLog(1);
}
OK, now my question. Obviously, I will need to use unique ID each time ReportIntoLog is called. First, I was trying to come up with sequential IDs manually as I was inserting ReportIntoLog into my service, but it soon became apparent that it is quite challenging when the number of times ReportIntoLog was present in the projects went over 100. So, I was wondering, is there any way to make compiler insert a unique ID for me? I don't care what is the value of that ID as long as it's unique and doesn't change from build to build. My idea was to use __LINE__, but when I change the code that value may change as well (in regards to previous builds/versions of the service).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|