Logging Function for DLLs using C

hello there,

Lately i was writing a DLL in C which to be called from .Net Web Services, and i stumble upon how can i debug the DLL. I found it more convenient to write debug output to file, but i need it pretty flexible to accept list of arguments. based on my quick and dirty approaches i ended up doing using vfprintf  or vfprintf_s and va_list. Below is the code. Enjoy 🙂

#include <stdio.h>

int WriteLOG(char * format,...)
{
    FILE * logFile;
    int status = 0;
    va_list arguments;

    va_start(arguments, format);

    fopen_s(&logFile,"D:\logfile.log","a+");
    if (logFile != NULL)
    {
        status = vfprintf_s(logFile,format,arguments);
        fclose(logFile);
    }
    va_end(arguments);    

    return status;
}
Posted in Programming and tagged , , , , , , , , , , . Bookmark the permalink. RSS feed for this post. Leave a trackback.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

Swedish Greys - a WordPress theme from Nordic Themepark.