Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon What are the benefits of using Microsoft.Extensions.Logging over MvxLog in MvvmCross


What are the benefits of using Microsoft.Extensions.Logging over MvxLog in MvvmCross


When comparing Microsoft.Extensions.Logging with MvxLog in the context of MvvmCross, several benefits emerge from using the former over the latter:

1. Extensibility and Flexibility: Microsoft.Extensions.Logging offers a highly extensible framework that allows easy integration with various third-party logging providers such as NLog, Serilog, and log4net. This flexibility is not inherently built into MvxLog, which was more limited in its ability to integrate with different logging frameworks[1][2]. With Microsoft.Extensions.Logging, you can easily switch between different logging providers without changing your application's code, making it more adaptable to different environments and requirements.

2. Dependency Injection Support: Microsoft.Extensions.Logging is designed to work seamlessly with dependency injection (DI), which is a core feature of many modern .NET applications, including those built with MvvmCross. This integration allows for easier unit testing and mocking of logging components, which is beneficial for maintaining robust test coverage[5][8]. MvxLog, while injectable, does not offer the same level of integration with DI frameworks as Microsoft.Extensions.Logging does.

3. Standardization and Community Support: Microsoft.Extensions.Logging is a widely adopted standard in the .NET ecosystem, which means it benefits from extensive community support and documentation. This standardization makes it easier for developers to understand and implement logging across different projects and platforms[2][11]. In contrast, MvxLog is specific to MvvmCross and might not be as widely recognized or supported outside of that framework.

4. Scalability and Performance: The architecture of Microsoft.Extensions.Logging is designed to handle large-scale applications efficiently. It provides features like log filtering and categorization, which can improve performance by reducing unnecessary log output[11]. While MvxLog is capable, it may not match the scalability and performance optimizations available in Microsoft.Extensions.Logging.

5. Configuration Flexibility: Microsoft.Extensions.Logging allows configuration through various means, including JSON files (e.g., `appsettings.json`), which provides a flexible way to manage log settings without recompiling the application[5]. This flexibility is particularly useful in environments where logging needs might change frequently.

6. Log Levels and Severity: Both frameworks support various log levels (e.g., Trace, Debug, Info, Warn, Error), but Microsoft.Extensions.Logging includes an additional `Critical` level and a `None` level for configuration purposes[11]. This provides more granular control over logging severity and configuration.

In summary, while MvxLog is a capable logging solution within the MvvmCross ecosystem, Microsoft.Extensions.Logging offers broader compatibility, extensibility, and community support, making it a more versatile choice for logging needs in modern .NET applications.

Citations:
[1] https://www.mvvmcross.com/documentation/fundamentals/logging-new
[2] https://putridparrot.com/blog/using-microsoft-extensions-logging/
[3] https://www.mvvmcross.com/documentation/advanced/customizing-using-App-and-Setup
[4] https://learn.microsoft.com/en-us/ef/core/logging-events-diagnostics/extensions-logging
[5] https://stackoverflow.com/questions/58209076/microsoft-extensions-logging-vs-nlog
[6] https://www.mvvmcross.com/mvvmcross-8.0.0-release/
[7] https://www.mvvmcross.com/documentation/fundamentals/viewmodel-lifecycle
[8] https://stackoverflow.com/questions/46483019/logging-from-static-members-with-microsoft-extensions-logging
[9] https://www.mvvmcross.com/logging
[10] https://stackoverflow.com/questions/17602137/mvvmcross-how-does-this-view-get-linked-to-the-viewmodel/17602246
[11] https://blog.stephencleary.com/2018/06/microsoft-extensions-logging-part-2-types.html