Ads by Lake Quincy Media

Wiki Navigation

 
Gibraltar - Learn about the best analysis tool for NLog

C logging API

NLog documentation is a Wiki, which allows registered users to edit its content.
If you want to contribute, please create a user account and contact Jarek to get edit access.

NLog supports a C/C++ logging API that can be used in scenarios that require the use of C/C++ components in .NET projects. Typical case is porting a legacy systen to .NET where some parts are rewritten in managed code while some remain unmanaged.

This API is available through NLogC.dll which is a mixed-mode (managed plus unmanaged) assembly. It provides the following set of exported functions:

//  
// ANSI functions 
//  
int NLog_ConfigureFromFileA(const char *fileName); 
void NLog_LogA(NLogLevel level, const char *loggerName, const char *logMessage, ...);  
void NLog_TraceA(const char *loggerName, const char *logMessage, ...);  
void NLog_DebugA(const char *loggerName, const char *logMessage, ...);  
void NLog_InfoA(const char *loggerName, const char *logMessage, ...);  
void NLog_WarnA(const char *loggerName, const char *logMessage, ...);  
void NLog_ErrorA(const char *loggerName, const char *logMessage, ...);  
void NLog_FatalA(const char *loggerName, const char *logMessage, ...);  
void NLog_LogVA(NLogLevel level, const char *loggerName, const char *logMessage, va_list args); 
 
//  
// Unicode functions 
//  
int NLog_ConfigureFromFileW(const wchar_t *fileName); 
void NLog_LogW(NLogLevel level, const wchar_t *loggerName, const wchar_t *logMessage, ...);  
void NLog_TraceW(const wchar_t *loggerName, const wchar_t *logMessage, ...);  
void NLog_DebugW(const wchar_t *loggerName, const wchar_t *logMessage, ...);  
void NLog_InfoW(const wchar_t *loggerName, const wchar_t *logMessage, ...);  
void NLog_WarnW(const wchar_t *loggerName, const wchar_t *logMessage, ...);  
void NLog_ErrorW(const wchar_t *loggerName, const wchar_t *logMessage, ...);  
void NLog_FatalW(const wchar_t *loggerName, const wchar_t *logMessage, ...);  
void NLog_LogVW(NLogLevel level, const wchar_t *loggerName, const wchar_t *logMessage, va_list args);For your convenience, the following defines which use a TCHAR data type are available:
 
// 
// TCHAR macros 
//  
#ifdef UNICODE 
 
#define NLog_Log NLog_LogW 
#define NLog_LogV NLog_LogVW 
#define NLog_Trace NLog_TraceW 
#define NLog_Debug NLog_DebugW 
#define NLog_Info NLog_InfoW 
#define NLog_Warn NLog_WarnW 
#define NLog_Error NLog_ErrorW 
#define NLog_Fatal NLog_FatalW 
#define NLog_ConfigureFromFile NLog_ConfigureFromFileW 
 
#else 
 
#define NLog_Log NLog_LogA 
#define NLog_LogV NLog_LogVA 
#define NLog_Trace NLog_TraceA 
#define NLog_Debug NLog_DebugA 
#define NLog_Info NLog_InfoA 
#define NLog_Warn NLog_WarnA 
#define NLog_Error NLog_ErrorA 
#define NLog_Fatal NLog_FatalA 
#define NLog_ConfigureFromFile NLog_ConfigureFromFileA 
 
#endif

Here’s the short summary of what these functions do (modulo their ANSI/UNICODE variants):

NLog_ConfigureFromFile(filename)

Configures NLog from the specified config file. You should call this function at the beginning of your program if you want to specify your own config file. If you don’t do this, NLog will attempt to find the config file the first time you use any of the logging functions using the logic described here.

NLog_Log(level, logger, logMessage, ...)

Writes the specified logMessage at the specified level to the specified logger. level is a NLogLevel enumeration value an can be one of the following constants:

  • NLOG_TRACE
  • NLOG_DEBUG
  • NLOG_INFO
  • NLOG_WARN
  • NLOG_ERROR
  • NLOG_FATAL

logMessage is a message to be written. It may include printf()-style parameters.

NLog_LogV(level, logger, logMessage, parameters) Same as NLog_Log() but lets you pass message parameters as va_list (useful for wrapping in your own logging layer).

NLog_Trace(logger, logMessage, ...) Equivalent to calling NLog_Log(NLOG_TRACE, logger, logMessage, ...)

NLog_Debug(logger,logMessage,...) Equivalent to calling NLog_Log(NLOG_DEBUG,logger,logMessage,...)

NLog_Info(logger,logMessage,...) Equivalent to calling NLog_Log(NLOG_INFO,logger,logMessage,...)

NLog_Warn(logger,logMessage,...) Equivalent to calling NLog_Log(NLOG_WARN,logger,logMessage,...)

NLog_Error(logger,logMessage,...) Equivalent to calling NLog_Log(NLOG_ERROR,logger,logMessage,...)

NLog_Fatal(logger,logMessage,...) Equivalent to calling NLog_Log(NLOG_FATAL,logger,logMessage,...)

The C/C++ API as-is is meant primarily to be wrapped by your own high-level logging API (every programmer has one, hasn’t he?). An example of such an API implemented as C++ class is provided in src/NLogC/NLogger.h.

Ads by Lake Quincy Media