forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntLib5Factory.cs
More file actions
68 lines (61 loc) · 2.77 KB
/
EntLib5Factory.cs
File metadata and controls
68 lines (61 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Fluent;
namespace ServiceStack.Logging.EntLib5
{
public class EntLib5Factory : LogWriterFactory, ILogFactory
{
/// <summary>
/// Initializes a new instance of the <see cref="EntLib5Factory"/> class.
/// </summary>
public EntLib5Factory() { }
/// <summary>
/// Initializes a new instance of the <see cref="EntLib5Factory"/> class.
/// </summary>
/// <param name="EntLib5ConfigurationFile">The enterprise library 5.0 configuration file to load and watch. Supercedes any configuration found in the Config file.</param>
public EntLib5Factory(string EntLib5ConfigurationFile)
{
// verify provided file exists
var fi = new System.IO.FileInfo(EntLib5ConfigurationFile);
if (fi.Exists)
{
var builder = new ConfigurationSourceBuilder();
var EntLib5ConfigurationSrc = new FileConfigurationSource(EntLib5ConfigurationFile, true);
builder.UpdateConfigurationWithReplace(EntLib5ConfigurationSrc);
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(EntLib5ConfigurationSrc);
}
}
/// <summary>
/// Initializes a new instance of the <see cref="EntLib5Factory"/> class.
/// </summary>
/// <param name="EntLib5ConfigurationSrc">The enterprise library 5.0 configuration source to load. Supercedes any configuration found in the Config file.</param>
public EntLib5Factory(IConfigurationSource EntLib5ConfigurationSrc)
{
// replace any settings from App.Config with the ones in the provided config source
var builder = new ConfigurationSourceBuilder();
builder.UpdateConfigurationWithReplace(EntLib5ConfigurationSrc);
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(EntLib5ConfigurationSrc);
}
/// <summary>
/// Gets the logger.
/// </summary>
/// <param name="type">The type.</param>
/// <returns></returns>
public ILog GetLogger(Type type)
{
return new EntLib5Logger(type);
}
/// <summary>
/// Gets the logger.
/// </summary>
/// <param name="typeName">Name of the type.</param>
/// <returns></returns>
public ILog GetLogger(string typeName)
{
return new EntLib5Logger(typeName);
}
}
}