@@ -140,43 +140,39 @@ public async Task<JToken> SendCommand(string commandName, JToken commandParamete
140
140
/// <param name="cancellationToken">A CancellationToken object to allow for cancellation of the command.</param>
141
141
/// <param name="millisecondsTimeout">The execution timeout of the command in milliseconds.</param>
142
142
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
143
+ /// <param name="loggingOptions">Logging preferences.</param>
143
144
/// <returns>A JToken based on a command created with the specified command name and parameters.</returns>
144
145
public async Task < JToken > SendCommand ( ICommand commandWithParameters ,
145
- CancellationToken cancellationToken = default , int ? millisecondsTimeout = null , bool throwExceptionIfResponseNotReceived = true )
146
+ CancellationToken cancellationToken = default , int ? millisecondsTimeout = null , bool throwExceptionIfResponseNotReceived = true ,
147
+ DevToolsCommandLoggingOptions loggingOptions = null )
146
148
{
147
149
return await SendCommand ( commandWithParameters . CommandName , JToken . FromObject ( commandWithParameters ) ,
148
- cancellationToken , millisecondsTimeout , throwExceptionIfResponseNotReceived ) ;
150
+ cancellationToken , millisecondsTimeout , throwExceptionIfResponseNotReceived , loggingOptions ) ;
149
151
}
150
152
151
153
private void LogCommand ( string commandName , JToken commandParameters , DevToolsCommandLoggingOptions loggingOptions = null )
152
154
{
153
- if ( loggingOptions == null )
154
- {
155
- loggingOptions = new DevToolsCommandLoggingOptions ( ) ;
156
- }
157
- if ( ! loggingOptions . Result . Enabled )
155
+ var logging = ( loggingOptions ?? new DevToolsCommandLoggingOptions ( ) ) . Command ;
156
+ if ( ! logging . Enabled )
158
157
{
159
158
return ;
160
159
}
161
160
if ( commandParameters . Any ( ) )
162
161
{
163
- Logger . LogByLevel ( loggingOptions . Command . LogLevel , "loc.browser.devtools.command.execute.withparams" , commandName , commandParameters . ToString ( ) ) ;
162
+ Logger . LogByLevel ( logging . LogLevel , "loc.browser.devtools.command.execute.withparams" , commandName , commandParameters . ToString ( ) ) ;
164
163
}
165
164
else
166
165
{
167
- Logger . LogByLevel ( loggingOptions . Command . LogLevel , "loc.browser.devtools.command.execute" , commandName ) ;
166
+ Logger . LogByLevel ( logging . LogLevel , "loc.browser.devtools.command.execute" , commandName ) ;
168
167
}
169
168
}
170
169
171
170
private void LogCommandResult ( JToken result , DevToolsCommandLoggingOptions loggingOptions = null )
172
171
{
173
- if ( loggingOptions == null )
174
- {
175
- loggingOptions = new DevToolsCommandLoggingOptions ( ) ;
176
- }
177
- if ( result . Any ( ) && loggingOptions . Result . Enabled )
172
+ var logging = ( loggingOptions ?? new DevToolsCommandLoggingOptions ( ) ) . Result ;
173
+ if ( result . Any ( ) && logging . Enabled )
178
174
{
179
- Logger . Info ( "loc.browser.devtools.command.execute.result" , result . ToString ( ) ) ;
175
+ Logger . LogByLevel ( logging . LogLevel , "loc.browser.devtools.command.execute.result" , result . ToString ( ) ) ;
180
176
}
181
177
}
182
178
}
0 commit comments