-
-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# How to log messages between Puppeteer-Sharp and Chromium | ||
|
||
_Contributors: [Darío Kondratiuk](https://www.hardkoded.com/)_ | ||
|
||
## Problem | ||
|
||
You want to log the messages sent by your app to Chromium and the messages received by Chromium. | ||
|
||
## Solution | ||
|
||
Add [Serilog.Extensions.Logging.File](https://www.nuget.org/packages/Serilog.Extensions.Logging.File/) Nuget package. | ||
|
||
First we need to create an `ILoggerFactory` | ||
|
||
```js | ||
private static ILoggerFactory GetLoggerFactory(string file) | ||
{ | ||
var factory = new LoggerFactory(); | ||
var filter = new FilterLoggerSettings | ||
{ | ||
{ "Connection", LogLevel.Trace } | ||
}; | ||
|
||
factory.WithFilter(filter).AddFile(file, LogLevel.Trace); | ||
|
||
return factory; | ||
} | ||
``` | ||
|
||
Now we can use `GetLoggerFactory` to inject a logger into Puppeteer. | ||
|
||
```cs | ||
using (var browser = await Puppeteer.LaunchAsync(browserOptions, GetLoggerFactory(fileName))) | ||
{ | ||
//Some code | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters