forked from ServiceStackV3/ServiceStack.Logging
/
Log4NetFactory.cs
65 lines (59 loc) · 2.25 KB
/
Log4NetFactory.cs
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
using System;
using System.IO;
namespace ServiceStack.Logging.Log4Net
{
/// <summary>
/// ILogFactory that creates an Log4Net ILog logger
/// </summary>
public class Log4NetFactory : ILogFactory
{
/// <summary>
/// Initializes a new instance of the <see cref="Log4NetFactory"/> class.
/// </summary>
public Log4NetFactory() : this(false) { }
/// <summary>
/// Initializes a new instance of the <see cref="Log4NetFactory"/> class.
/// </summary>
/// <param name="configureLog4Net">if set to <c>true</c> [will use the xml definition in App.Config to configure log4 net].</param>
public Log4NetFactory(bool configureLog4Net)
{
if (configureLog4Net)
{
log4net.Config.XmlConfigurator.Configure();
}
}
/// <summary>
/// Initializes a new instance of the <see cref="Log4NetFactory"/> class.
/// </summary>
/// <param name="log4NetConfigurationFile">The log4 net configuration file to load and watch. If not found configures from App.Config.</param>
public Log4NetFactory(string log4NetConfigurationFile)
{
//Restart logging if necessary
log4net.Repository.ILoggerRepository rootRepository = log4net.LogManager.GetRepository();
if (rootRepository != null)
rootRepository.Shutdown();
if (File.Exists(log4NetConfigurationFile))
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(log4NetConfigurationFile));
else
log4net.Config.XmlConfigurator.Configure();
}
/// <summary>
/// Gets the logger.
/// </summary>
/// <param name="type">The type.</param>
/// <returns></returns>
public ILog GetLogger(Type type)
{
return new Log4NetLogger(type);
}
/// <summary>
/// Gets the logger.
/// </summary>
/// <param name="typeName">Name of the type.</param>
/// <returns></returns>
public ILog GetLogger(string typeName)
{
return new Log4NetLogger(typeName);
}
}
}