diff --git a/src/client/Microsoft.Rest.ClientRuntime.Log4Net/Log4NetTracingInterceptor.cs b/src/client/Microsoft.Rest.ClientRuntime.Log4Net/Log4NetTracingInterceptor.cs
index 2882fca12b8dd..5cb49f6eb60a7 100644
--- a/src/client/Microsoft.Rest.ClientRuntime.Log4Net/Log4NetTracingInterceptor.cs
+++ b/src/client/Microsoft.Rest.ClientRuntime.Log4Net/Log4NetTracingInterceptor.cs
@@ -17,28 +17,39 @@ public class Log4NetTracingInterceptor : IServiceClientTracingInterceptor
{
private ILog _logger;
+ ///
+ /// Initializes a new instance of the class with log4net logger.
+ ///
+ /// log4net logger.
+ public Log4NetTracingInterceptor(ILog logger)
+ {
+ _logger = logger;
+ }
+
///
/// Initializes a new instance of the class with configuration file.
///
/// The configuration file absolute path.
public Log4NetTracingInterceptor(string filePath)
+ : this(LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType))
{
- _logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
-
- if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
- {
- log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(filePath));
- }
- else
+ if (!string.IsNullOrEmpty(filePath))
{
- throw new FileNotFoundException(filePath);
+ if (File.Exists(filePath))
+ {
+ log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(filePath));
+ }
+ else
+ {
+ throw new FileNotFoundException(filePath);
+ }
}
}
///
/// Initializes a new instance of the class without configuration file.
///
- public Log4NetTracingInterceptor() : this(null)
+ public Log4NetTracingInterceptor() : this(string.Empty)
{
}
diff --git a/src/client/Microsoft.Rest.ClientRuntime.Log4Net/README.md b/src/client/Microsoft.Rest.ClientRuntime.Log4Net/README.md
index c6c1f8a1b2d43..b7183550d27bb 100644
--- a/src/client/Microsoft.Rest.ClientRuntime.Log4Net/README.md
+++ b/src/client/Microsoft.Rest.ClientRuntime.Log4Net/README.md
@@ -35,7 +35,8 @@ Using Log4Net for AutoRest Generated Clients:
```
B) Passing the config file name to ```Log4NetTracingInterceptor``` constructor.
-3- Last step is to register the logger into the ServiceClientTracing by having this line called at the start of the application:
+3- Last step is to register the logger into the ServiceClientTracing and enable tracing by having these lines called at the start of the application:
```csharp
ServiceClientTracing.AddTracingInterceptor(new Log4NetTracingInterceptor());
+ ServiceClientTracing.IsEnabled = true;
```
\ No newline at end of file