Skip to content

Commit 45efdfc

Browse files
committed
docs: Update logging guide for new IVelopackLogger API
Refactors examples and explanations to use Velopack.Logging.IVelopackLogger with VelopackApp and UpdateManager, replacing Microsoft.Extensions.Logging.ILogger.
1 parent f2dcf00 commit 45efdfc

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

docs/troubleshooting/debugging.mdx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,39 @@ Find or configure application logs to find runtime issues.
55
All parts of Velopack have logging built in to help troubleshoot issues, and you should provide these logs when opening a GitHub issue about a potential bug.
66

77
## Logging UpdateManager
8-
You should provide an instance of `Microsoft.Extensions.Logging.ILogger` to `VelopackApp.Run(ILogger)` and to `UpdateManager` to record potential issues. If you are not using Microsoft Hosting or Logging already, it is very simple to implement this interface yourself and log to a file, or integrate with another logging framework.
9-
8+
You can provide your own instance of `Velopack.Logging.IVelopackLogger` to `VelopackApp.SetLogger(IVelopackLogger)`. A logger can also be provided to the `UpdateManager` via its `IVelopackLocator``Log` property. The built-in locators support passing in an `IVelopackLocator` instance to their constructors.
9+
You cna also create a default locator using the `Velopack.Locators.VelopackLocator.CreateDefaultForPlatform(ILogger)` method.
1010
For example:
1111
```cs
12-
using Microsoft.Extensions.Logging;
1312

1413
// ...
1514
16-
class ConsoleLogger : ILogger
15+
public class ConsoleVelopackLogger : IVelopackLogger
1716
{
18-
public IDisposable BeginScope<TState>(TState state) where TState : notnull => null;
19-
public bool IsEnabled(LogLevel logLevel) => true;
20-
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
21-
=> Console.WriteLine(formatter(state, exception));
17+
public void Log(VelopackLogLevel logLevel, string? message, Exception? exception)
18+
{
19+
var logMessage = $"[{DateTime.Now.ToShortTimeString()}] [{logLevel}] {message}";
20+
if (exception != null) {
21+
logMessage += Environment.NewLine + exception;
22+
}
23+
24+
Console.WriteLine(logMessage);
25+
}
2226
}
2327

2428
// ...
29+
using Velopack.Logging;
30+
31+
VelopackApp.Build()
32+
.SetLogger(new ConsoleVelopackLogger())
33+
.Run();
34+
35+
// ...
36+
using Velopack.Locators;
37+
using Velopack.Logging;
2538

26-
new UpdateManager("https://path.to/your-updates", logger: new ConsoleLogger());
39+
var locator = VelopackLocator.CreateDefaultForPlatform(new ConsoleVelopackLogger());
40+
var updateManager = new UpdateManager("your-update-url", null, locator);
2741
```
2842

2943
## Logging in the Velopack binaries

0 commit comments

Comments
 (0)