I am trying to use Microsoft's Common Log File System (CLFS) API. My code looks like this.
CLFS_MGMT_POLICY log_policy;
CLFS_INFORMATION log_info;
ULONG info_size = sizeof (log_info);
ULONGLONG desired_size;
ULONGLONG resulting_size;
data->log_handle = CreateLogFile (
helpers::towstring (data->log_name).c_str (), GENERIC_WRITE,
FILE_SHARE_DELETE | FILE_SHARE_WRITE | FILE_SHARE_READ, 0,
OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE);
if (data->log_handle == INVALID_HANDLE_VALUE)
{
loglog_win32_error (LOG4CPLUS_TEXT ("CreateLogFile()"));
goto error;
}
if (! RegisterManageableLogClient (data->log_handle, 0))
{
loglog_win32_error (LOG4CPLUS_TEXT ("RegisterManageableLogClient()"));
goto error;
}
The CreateLogFile() function executes fine and I can even see a .blf file appear on file system. But RegisterManageableLogClient() returns with error and GetLastError() returns value 5 which is "Access is denied." This code is nearly identical to example on MSDN.
I cannot figure out why is the call to RegisterManageableLogClient() failing.
UPDATE:
The problem was missing GENERIC_READ for CreateLogFile().
The problem was missing
GENERIC_READforCreateLogFile().