COM logging API
If you want to contribute, please create a user account and contact Jarek to get edit access.
(Redirected from COM Logging API)
NLog features a COM Interop API tha can be used to provide logging for legacy COM applications or components that are deployed as part of a .NET solution.
COM support is available through 2 COM classes:
- NLog.LogManager which lets you perform basic configuration
- NLog.Logger which does the actual logging.
COM components are supported for many languages, both scripting and compiled. Basic usage is similar to the .NET API, with the following exceptions:
- Instances of loggers are created directly, you don’t need to use LogManager to get them.
- Because COM classes don’t support passing parameters at construction time, you need to set each logger’s name by setting its LoggerName
- Passing of format arguments isn’t supported
- Logger levels (arguments to the Log() method) are passed as strings instead of enumeration values – this provides maximum compatibility
with scripting environments.
The following example demonstrates the use of NLog COM API for JScript.
var logmanager = new ActiveXObject("NLog.LogManager"); WScript.Echo("Loading config from file 'config8.nlog'..."); logmanager.InternalLogToConsole = true; logmanager.InternalLogFile = "internal_log.txt"; logmanager.InternalLogLevel = "Info"; logmanager.LoadConfigFromFile("config8.nlog"); var logger = new ActiveXObject("NLog.Logger"); logger.LoggerName = "TestLogger"; logger.Log("Trace", "This is a trace message"); logger.Log("Debug", "This is a debugging message"); logger.Log("Info", "This is an information message"); logger.Log("Warn", "This is a warning message"); logger.Log("Error", "This is an error"); logger.Log("Fatal", "This is a fatal message"); logger.Trace("This is a trace message"); logger.Debug("This is a debugging message"); logger.Info("This is an information message"); logger.Warn("This is a warning message"); logger.Error("This is an error"); logger.Fatal("This is a fatal message"); WScript.Echo("Loading config from file 'config8a.nlog'..."); logmanager.InternalLogToConsole = false; logmanager.InternalLogFile = "internal_log.txt"; logmanager.InternalLogLevel = "Fatal"; logmanager.LoadConfigFromFile("config8a.nlog"); logger.Log("Trace", "This is a trace message"); logger.Log("Debug", "This is a debugging message"); logger.Log("Info", "This is an information message"); logger.Log("Warn", "This is a warning message"); logger.Log("Error", "This is an error"); logger.Log("Fatal", "This is a fatal message"); logger.Trace("This is a trace message"); logger.Debug("This is a debugging message"); logger.Info("This is an information message"); logger.Warn("This is a warning message"); logger.Error("This is an error"); logger.Fatal("This is a fatal message");




