How do I implement custom logging?
The Catalog app has a complete code example demonstrating custom logging.
This article shows how to implement logging to the Visual Studio output window.
Implement a class derived from ICustomLogger
, overriding the various log methods for each log level (Warn
, Error
, etc.):
class CustomLogger : ICustomLogger { private static void Log(string tag, string message) { System.Diagnostics.Debug.WriteLine($"{tag}: {message}"); } public void Critical(string tag, string message) { Log(tag, message); } public void Error(string tag, string message) { Log(tag, message); } public void Warn(string tag, string message) { Log(tag, message); } public void Info(string tag, string message) { Log(tag, message); } public void Debug(string tag, string message) { Log(tag, message); } public void Trace(string tag, string message) { Log(tag, message); } }
Then, assign an instance of it to the Nutrient Logger
:
// Set up your own custom logger. var customLogger = new CustomLogger(); // Set it in the Nutrient logger. var logger = Logger.Instance; logger.CustomLogger = customLogger; // Choose your own log level. Debug is useful for sending reports to us. logger.CurrentLevel = Level.Debug; // You can use the logger for your own logs too. logger.Info("MYAPP", "Created customer logger and set log level to Debug");
Consider logging your application to a file that users can send to you. This typically saves our customers a lot of time when diagnosing issues.