I was recently trying to store my Enterprise Library configuration in a common location, and read some people talking about SqlConfigurationSource that comes as a sample with the Enterprise Library. It took me forever to get my hands on the actual .dll and T-SQL code needed to make use of this ... so I thought I would try to save someone else the pain of searching for that stuff, installing, and compiling the samples. Here are links to the compiled dll, along with the T-SQL code needed to setup the database to be able to store the config settings.
Here is an example of the type of code you should be able to use to dynamically log the config settings from a SQL database:
var source = new SqlConfigurationSource(
"ConnectionString",
"EntLib_GetStoredProcName",
"Entlib_SetStoredProcName",
"Entlib_RefreshStoredProcName",
"Entlib_RemoveStorecProcName");
var factory = new LogWriterFactory(source);
var writer = factory.Create();
writer.Write(logEntry);
Microsoft.Practices.EnterpriseLibrary.SqlConfigurationSource.dll (26.5 KB)
SqlConfiguration.zip (.99 KB)
To read more about how this works, check out this: http://geekswithblogs.net/akraus1/articles/62869.aspx.
Also, a tool named "SQL Config Convertor" really helped me out. It is an older open source project that helps import the configuration settings that are currently stored in a .config file into the new database structure in the proper format. It was a little bit painful to get working, but I did finally get it up and running and it still saved me a lot of time.
http://code.msdn.microsoft.com/SqlConfigConverter
Here is an example of the data that the configuration table would store:
| section_name |
section_type |
section_value |
lastmoddate |
| loggingConfiguration |
Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral |
<?xml version="1.0" encoding="utf-16"?><SerializableConfigurationSection name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true" revertImpersonation="true"> <listeners> <clear /> <add source="Enterprise Library Logging" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Formatted EventLog TraceListener" /> </listeners> <formatters> <clear /> <add template="Timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}
EventId: {eventid}
Severity: {severity}
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}
)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Text Formatter" /> </formatters> <logFilters> <clear /> </logFilters> <categorySources> <clear /> <add switchValue="All" autoFlush="true" name="General"> <listeners> <clear /> <add name="Formatted EventLog TraceListener" /> </listeners> </add> </categorySources> <specialSources> <allEvents switchValue="All" autoFlush="true" name="All Events"> <listeners> <clear /> <add name="Formatted EventLog TraceListener" /> </listeners> </allEvents> <notProcessed switchValue="All" autoFlush="true" name="Unprocessed Category"> <listeners> <clear /> </listeners> </notProcessed> <errors switchValue="All" autoFlush="true" name="Logging Errors & Warnings"> <listeners> <clear /> <add name="Formatted EventLog TraceListener" /> </listeners> </errors> </specialSources> </SerializableConfigurationSection> |
9/17/2009 2:44:42 PM |