Logging in DotNetBrowser is disabled by default. To get DotNetBrowser log messages you must enable logging. Log messages can be printed into console or file. Here's example of how log messages look like:
11/24/2015 4:13:55 PM [] Information Browser - OS name: Microsoft Windows 7 Professional Service Pack 1 11/24/2015 4:13:55 PM [] Information Browser - OS version: 4.0.30319.18444 11/24/2015 4:13:55 PM [] Information Browser - DotNetBrowser build: 1.5.2.0 11/24/2015 4:13:55 PM [] Information IPC - Starting IPC... 11/24/2015 4:13:55 PM [] Information IPC - Starting IPC Server... 11/24/2015 4:13:55 PM [] Information IPC - Starting IPC Process... 11/24/2015 4:13:55 PM [IPC Process Thread] Information Process - Start Chromium process... 11/24/2015 4:13:55 PM [IPC Process Thread] Information Process - Command line: C:\Users\Ikryanov\AppData\Local\Temp\dotnetbrowser-chromium-43.0.2357.52.1.5.1\DotNetBrowser.Chromium.exe1101 14128 11/24/2015 4:13:56 PM [] Information IPC - Socket writer thread started 11/24/2015 4:13:56 PM [] Information IPC - Socket reader thread started 11/24/2015 4:13:56 PM [Socket reader thread] Information IPC - READ: OnHelloMessage{type=OnHelloMessage, uid=1, message='cid:0,type:Main'}, 11/24/2015 4:13:56 PM [] Information IPC - IPC is started. 11/24/2015 4:13:56 PM [Socket writer thread] Information IPC - WRITE: SetNetworkDelegateConfigMessage{type=SetNetworkDelegateConfig, uid=0, browserContextId=-1, DisableMessages=True}, SocketInfo{channelId=0, browserId=-1, channelType=Main} 11/24/2015 4:13:56 PM [Socket writer thread] Information IPC - WRITE: CreateBrowserMessage{type=CreateBrowser, uid=1, channelId=0, contextId=-1, cacheDir='C:\Users\Ikryanov\AppData\Local\Temp\dotnetbrowser-chromium-43.0.2357.52.1.5.1\data\Cache', memoryDir='', dataDir='C:\Users\Ikryanov\AppData\Local\Temp\dotnetbrowser-chromium-43.0.2357.52.1.5.1\data', currentLocale='en-us', proxyType=-1, proxyRules='', proxyBypassRules='', proxyAutoConfigURL='', defaultZoomLevel='0', isOffScreenMode='False'}, SocketInfo{channelId=0, browserId=-1, channelType=Main}
Logging to Console
LoggerProvider.Instance.LoggingEnabled = true; LoggerProvider.Instance.ConsoleLoggingEnabled = true;
Logging to File
LoggerProvider.Instance.LoggingEnabled = true; LoggerProvider.Instance.FileLoggingEnabled = true; LoggerProvider.Instance.OutputFile = "D:/DotNetBrowser.log";
You can use both absolute or relative path to the *.log
file. DotNetBrowser prints log messages to the end of the file.
Chromium logging
Chromium engine has its own logging. You can enable it using the following source code.
LoggerProvider.Instance.FileLoggingEnabled = true; LoggerProvider.Instance.ChromiumLogFile = "D:/chromium.log";
It is recommended to use an absolute path to the log file. Please note, that Chromium engine rewrites log file on every launch.
Also, you can enable the verbose Chromium logging using the following switch.
BrowserPreferences.SetChromiumSwitches("--v=1");
Please note that the Chromium switches should be specified before any Browser instance is created.
Redirecting DotNetBrowser Logging
DotNetBrowser uses TraceSource for logging, and you can attach custom TraceListeners to perform logging redirection.
The following sample demonstrates redirecting DotNetBrowser logs to log4net:
App.config
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.diagnostics> <trace autoflush="true"/> <sources> <source name="IPC" switchValue="All"> <listeners> <add name="myListener" type="ConsoleApplication.Log4netTraceListener, ConsoleApplication"/> </listeners> </source> <source name="Browser" switchValue="All"> <listeners> <add name="myListener" type="ConsoleApplication.Log4netTraceListener, ConsoleApplication"/> </listeners> </source> <source name="Process" switchValue="All"> <listeners> <add name="myListener" type="ConsoleApplication.Log4netTraceListener, ConsoleApplication"/> </listeners> </source> </sources> </system.diagnostics> </configuration>
C#
Log4netTraceListener.cs
namespace ConsoleApplication { public class Log4netTraceListener : System.Diagnostics.TraceListener { private readonly log4net.ILog _log; public Log4netTraceListener() { _log = log4net.LogManager.GetLogger("DotNetBrowser"); } public Log4netTraceListener(log4net.ILog log) { _log = log; } public override void Write(string message) { if (_log != null) { _log.Debug(message); } } public override void WriteLine(string message) { if (_log != null) { _log.Debug(message); } } } }
VB.NET
Log4netTraceListener.vb
Namespace ConsoleApplication Public Class Log4netTraceListener Inherits System.Diagnostics.TraceListener Private ReadOnly _log As log4net.ILog Public Sub New() _log = log4net.LogManager.GetLogger("DotNetBrowser") End Sub Public Sub New(ByVal log As log4net.ILog) _log = log End Sub Public Overrides Sub Write(ByVal message As String) If _log IsNot Nothing Then _log.Debug(message) End If End Sub Public Overrides Sub WriteLine(ByVal message As String) If _log IsNot Nothing Then _log.Debug(message) End If End Sub End Class End Namespace