log4xojolib
Log4Xojo is a lightweight and thread-safe logging framework designed for Xojo applications. It provides robust logging capabilities, including support for multiple log levels, dynamic log file naming, file rotation, and asynchronous logging using a background thread. To learn more about this class, check out: https://blog.xojo.com/2024/11/26/log4xojo-a-more-powerful-way-to-manage-your-app-logging/. Contributions are welcome! This project is licensed under the MIT License. See the LICENSE file for details This class was inspired by popular logging frameworks such as Log4J and Log4Net, adapted for the Xojo ecosystem.
Features
Debug, Info, Warning, Error, and Critical levels.
DebugLog)SystemLog)FileLog)All)
Usage Example
Basic Example
// Create a logger instance
Var appLog As New Log4Xojo("AppLog")
// Set the base location for log files
appLog.SetLogFilePath(SpecialFolder.Documents)
// Configure the logger
appLog.SetLogLevel(Log4Xojo.LogLevel.Info)
appLog.SetLogDestinations(Log4Xojo.LogDestination.FileLog)
// Log some messages
appLog.Log("Application started", Log4Xojo.LogLevel.Info)
appLog.Log("This is a warning", Log4Xojo.LogLevel.Warning)
appLog.Log("Critical error occurred", Log4Xojo.LogLevel.Critical, CurrentMethodName)
// Stop logging when done
appLog.StopLogging()
Rotating Logs by Size
// Set maximum log file size (e.g., 1 MB)
appLog.SetMaxLogFileSize(1024 * 1024) // 1 MB
// Set the maximum number of backup files
appLog.SetMaxBackupFiles(5)
Contributing
License
Acknowledgements