Skip to content

Commit

Permalink
Fix exception in Log4NetTracingInterceptor default constructor (Azure…
Browse files Browse the repository at this point in the history
…#1237)

* Make it possible to instantiate Log4NetTracingInterceptor without configuration file.

* Mention ServiceClientTracing.IsEnabled in README file.
  • Loading branch information
older authored and tbombach committed Jul 13, 2016
1 parent 5d64b77 commit d8ef424
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,39 @@ public class Log4NetTracingInterceptor : IServiceClientTracingInterceptor
{
private ILog _logger;

/// <summary>
/// Initializes a new instance of the <see cref="Log4NetTracingInterceptor" /> class with log4net logger.
/// </summary>
/// <param name="logger">log4net logger.</param>
public Log4NetTracingInterceptor(ILog logger)
{
_logger = logger;
}

/// <summary>
/// Initializes a new instance of the <see cref="Log4NetTracingInterceptor" /> class with configuration file.
/// </summary>
/// <param name="filePath">The configuration file absolute path.</param>
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);
}
}
}

/// <summary>
/// Initializes a new instance of the <see cref="Log4NetTracingInterceptor" /> class without configuration file.
/// </summary>
public Log4NetTracingInterceptor() : this(null)
public Log4NetTracingInterceptor() : this(string.Empty)
{
}

Expand Down
3 changes: 2 additions & 1 deletion src/client/Microsoft.Rest.ClientRuntime.Log4Net/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
```

0 comments on commit d8ef424

Please sign in to comment.