Skip to content

Commit 9dc596c

Browse files
committed
Merge pull request #9 from KevinHoward/master
Added Logging Provider for the Microsoft Enterprise Library 5.0.
2 parents ec12eb9 + 88e0aaa commit 9dc596c

17 files changed

+1378
-175
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ It allows your business logic to bind to an easily-mockable and testable depende
77

88
## Download on NuGet
99

10-
Currently there are 5 different .NET logging providers available on NuGet:
10+
Currently there are 6 different .NET logging providers available on NuGet:
1111

1212
#### Install-Package [ServiceStack.Logging.NLog](https://nuget.org/packages/ServiceStack.Logging.NLog)
1313
#### Install-Package [ServiceStack.Logging.Elmah](https://nuget.org/packages/ServiceStack.Logging.Elmah)
1414
#### Install-Package [ServiceStack.Logging.Log4Net](https://nuget.org/packages/ServiceStack.Logging.Log4Net)
1515
#### Install-Package [ServiceStack.Logging.Log4Netv129](https://nuget.org/packages/ServiceStack.Logging.Log4Netv129)
1616
#### Install-Package [ServiceStack.Logging.EventLog](https://nuget.org/packages/ServiceStack.Logging.EventLog)
17+
#### Install-Package [ServiceStack.Logging.EntLib5](https://nuget.org/packages/ServiceStack.Logging.EntLib5)
1718

1819
Note: The ConsoleLogger and DebugLogger and are already built-in and bind to .NET Framework's Console and Debug loggers
1920

@@ -39,6 +40,7 @@ ServiceStack.Logging also includes adapters for the following logging providers:
3940
* NLog
4041
* Log4Net 1.2.10+
4142
* Log4Net 1.2.9
43+
* Enterprise Library 5.0
4244
* EventLog
4345
* Console Log
4446
* Debug Log
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<configSections>
4+
<section name="loggingConfiguration"
5+
type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
6+
requirePermission="true" />
7+
<section name="dataConfiguration"
8+
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
9+
requirePermission="true" />
10+
</configSections>
11+
<!--Flat File Trace Listener-->
12+
13+
<loggingConfiguration name="Logging Application Block"
14+
tracingEnabled="true"
15+
defaultCategory="Default Category"
16+
logWarningsWhenNoCategoriesMatch="true">
17+
<formatters>
18+
<add name="Text Formatter"
19+
template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}"
20+
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
21+
/>
22+
<add name="One Line Formatter"
23+
template="{timestamp(local)} Cat: {category} Pri: {priority} EId: {eventid} Sev: {severity} {message} Title:{title} Machine: {machine} Application Domain: {appDomain} Process Id: {processId} Process Name: {processName} Win32 Thread Id: {win32ThreadId} Thread Name: {threadName} Extended Properties: {dictionary({key} - {value})}"
24+
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
25+
/>
26+
</formatters>
27+
<listeners>
28+
<!-- Trace Listener to log entry to the System Event log using the Text Formatter format from above -->
29+
<add name="Formatted EventLog TraceListener"
30+
source="Enterprise Library Logging"
31+
formatter="Text Formatter"
32+
log="Application"
33+
machineName=""
34+
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
35+
traceOutputOptions="None"
36+
filter="All"
37+
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
38+
/>
39+
<!-- Trace Listener to log entry to a Rolling Text File log using the One Line Formatter format from above -->
40+
<add name="Rolling Flat File"
41+
fileName="Logger.log"
42+
formatter="One Line Formatter"
43+
rollFileExistsBehavior="Increment"
44+
rollInterval="Midnight"
45+
rollSizeKB="10000"
46+
timeStampPattern="yyyy-MM-dd"
47+
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
48+
traceOutputOptions="None"
49+
filter="All"
50+
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
51+
/>
52+
</listeners>
53+
<logFilters>
54+
<add name="LogEnabled Filter"
55+
type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
56+
enabled="true"
57+
/>
58+
</logFilters>
59+
<categorySources>
60+
<!-- Log all Warnings to the System Event Log -->
61+
<add name="Default Category"
62+
switchValue="Warning">
63+
<listeners>
64+
<add name="Formatted EventLog TraceListener" />
65+
</listeners>
66+
</add>
67+
</categorySources>
68+
<specialSources>
69+
<!-- Log everyting not specified above to the Rolling Text File log -->
70+
<allEvents switchValue="All" name="All Events">
71+
<listeners>
72+
<add name="Rolling Flat File" />
73+
</listeners>
74+
</allEvents>
75+
<errors switchValue="All" name="Logging Errors &amp; Warnings">
76+
<listeners>
77+
<add name="Formatted EventLog TraceListener" />
78+
</listeners>
79+
</errors>
80+
</specialSources>
81+
</loggingConfiguration>
82+
</configuration>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Configuration;
3+
using Microsoft.Practices.EnterpriseLibrary.Logging;
4+
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
5+
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
6+
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Fluent;
7+
8+
namespace ServiceStack.Logging.EntLib5
9+
{
10+
public class EntLib5Factory : LogWriterFactory, ILogFactory
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="EntLib5Factory"/> class.
14+
/// </summary>
15+
public EntLib5Factory() { }
16+
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="EntLib5Factory"/> class.
19+
/// </summary>
20+
/// <param name="EntLib5ConfigurationFile">The enterprise library 5.0 configuration file to load and watch. Supercedes any configuration found in the Config file.</param>
21+
public EntLib5Factory(string EntLib5ConfigurationFile)
22+
{
23+
// verify provided file exists
24+
var fi = new System.IO.FileInfo(EntLib5ConfigurationFile);
25+
if (fi.Exists)
26+
{
27+
var builder = new ConfigurationSourceBuilder();
28+
var EntLib5ConfigurationSrc = new FileConfigurationSource(EntLib5ConfigurationFile, true);
29+
30+
builder.UpdateConfigurationWithReplace(EntLib5ConfigurationSrc);
31+
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(EntLib5ConfigurationSrc);
32+
}
33+
}
34+
35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="EntLib5Factory"/> class.
37+
/// </summary>
38+
/// <param name="EntLib5ConfigurationSrc">The enterprise library 5.0 configuration source to load. Supercedes any configuration found in the Config file.</param>
39+
public EntLib5Factory(IConfigurationSource EntLib5ConfigurationSrc)
40+
{
41+
// replace any settings from App.Config with the ones in the provided config source
42+
var builder = new ConfigurationSourceBuilder();
43+
builder.UpdateConfigurationWithReplace(EntLib5ConfigurationSrc);
44+
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(EntLib5ConfigurationSrc);
45+
}
46+
47+
48+
/// <summary>
49+
/// Gets the logger.
50+
/// </summary>
51+
/// <param name="type">The type.</param>
52+
/// <returns></returns>
53+
public ILog GetLogger(Type type)
54+
{
55+
return new EntLib5Logger(type);
56+
}
57+
58+
/// <summary>
59+
/// Gets the logger.
60+
/// </summary>
61+
/// <param name="typeName">Name of the type.</param>
62+
/// <returns></returns>
63+
public ILog GetLogger(string typeName)
64+
{
65+
return new EntLib5Logger(typeName);
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)