Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
```