I'm trying to implement a C# method that can log a message with a format string and a variable number of printf-style arguments. Ideally, it would work identically to the C function I pasted below, although idiomatic to C# of course.
static
void
LogMessage(const char * iFormat, ...)
{
va_list argp;
FILE * fp;
fp = fopen("log.txt", "a");
if (fp != NULL) {
va_start(argp, iFormat);
vfprintf(fp, iFormat, argp);
va_end(argp);
fprintf(fp, "\n");
fclose(fp);
}
}
This function is convenient for me, as it allows me to make the following calls:
LogMessage("Testing");
LogMessage("Testing %s", "1 2 3");
LogMessage("Testing %d %d %d", 1, 2, 3);