LogHelper (VB.NET)

A comprehensive guide to the LogHelper (VB.NET)

LogHelper (VB.NET)

A comprehensive logging utility class that provides structured logging capabilities with multiple output targets and log levels.

Features

Installation

Add the LogHelper.vb file to your project.

Imports JVR.Helpers

Usage Examples

Basic Logging

Dim logger As New LogHelper()

' Log messages at different levels
logger.Debug("Debug message")
logger.Info("Information message")
logger.Warning("Warning message")
logger.Error("Error message")
logger.Fatal("Fatal error message")

Structured Logging

Dim logger As New LogHelper()

' Log with context
logger.LogWithContext("User login", New With {
    .UserId = "123",
    .Username = "john.doe",
    .LoginTime = DateTime.Now
})

' Log with custom fields
Dim fields As New Dictionary(Of String, Object) From {
    {"Amount", 100.5},
    {"Currency", "USD"},
    {"TransactionId", "TX123"}
}
logger.LogWithFields("Payment processed", fields)

Performance Logging

Dim logger As New LogHelper()

Using logger.MeasureOperation("Database Query")
    ' Perform database operation
    ' Duration will be automatically logged
End Using

' Log with custom timer
logger.LogPerformance("API Call", stopwatch.Elapsed)

API Reference

Basic Logging Methods

Structured Logging

Performance Logging

Configuration

Advanced Features

Log Levels

  1. Debug: Detailed information for debugging
  2. Info: General information about application flow
  3. Warning: Potentially harmful situations
  4. Error: Error events that might still allow application to continue
  5. Fatal: Very severe error events that may lead to application termination

Dependencies

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

Version History

Legal Disclaimer

This documentation and associated helper scripts are provided "as is" without warranty of any kind, either express or implied.

  1. The code examples and helper functions are for illustrative purposes only.
  2. Users should thoroughly test any implementation in their specific environment.
  3. The authors are not responsible for any issues or damages arising from the use of these scripts.
  4. Always follow security best practices and your organization's coding guidelines.