Custom app.config wont load - c#

I get this error:
Failure:
System.TypeInitializationException: The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section ServiceSettings/TycheConnectionString. (C:\KR_workspace\Alpha\Tyche\Applications\KPlusSynchronizer\KPlusSynchronizer\KPlusSynchronizerConsole\bin\Debug\KPlusSynchronizerConsole.vshost.exe.config line 17)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_Sources()
at System.Diagnostics.TraceSource.Initialize()
at System.Diagnostics.TraceSource.get_Switch()
at System.Transactions.Diagnostics.DiagnosticTrace..cctor()
--- End of inner exception stack trace ---
at System.Transactions.Transaction.get_Current()
at System.Data.Common.ADP.IsSysTxEqualSysEsTransaction()
at System.Data.Common.ADP.NeedManualEnlistment()
at System.Data.Odbc.OdbcConnection.Open()
at KPlusSynchronizer.Kplus.GetDataFromKplus(String kplusConnection, String sp) in c:\KR_workspace\Alpha\Tyche\Applications\KPlusSynchronizer\KPlusSynchronizer\KPlusSynchronizer\KPlus\Kplus.cs:line 24
at KPlusSynchronizer.Kplus..ctor(String kplusConnection, String sp) in c:\KR_workspace\Alpha\Tyche\Applications\KPlusSynchronizer\KPlusSynchronizer\KPlusSynchronizer\KPlus\Kplus.cs:line 16
at KPlusSynchronizer.Synchronizer.Synchronize(String tycheTable, String tycheSp, String kplusSp) in c:\KR_workspace\Alpha\Tyche\Applications\KPlusSynchronizer\KPlusSynchronizer\KPlusSynchronizer\KPlusSynchronizer.cs:line 34:
when I'm running my application. This is my app config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="ServiceSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="KPlusSynchronizerConsole.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
<sectionGroup name="TablesToSynchronize" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="KPlusSynchronizerConsole.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<ServiceSettings>
<TycheConnectionString value="Data Source=xxxxx;Initial Catalog=xxxxxx;Integrated Security=True" />
<KplusConnectionString value="Driver={Adaptive Server Enterprise};UID=xxxxx;PWD=xxxxx;Database=xxxxxx;Server=xxxxx;Port=4130;" />
<LogFiles value="true" />
</ServiceSettings>
<TablesToSynchronize>
<Table name="Table1" tycheSp="xxxxx" kplusSp="xxxx"/>
<Table name="Table2" tycheSp="xxxxx" kplusSp="xxxx"/>
<Table name="Table3" tycheSp="xxxxx" kplusSp="xxxx"/>
</TablesToSynchronize>
</configuration>
So the error is thrown when I'm opening connection to a DB using the connectionstring. I would like some help how to set this up. Do I need both configSections? Is this even possible?
I would like to use this kind om format instead of appSettings

Try
<ServiceSettings>
<KPlusSynchronizerConsole.Properties.Settings>
<TycheConnectionString value="Data Source=xxxxx;Initial Catalog=xxxxxx;Integrated Security=True" />
<KplusConnectionString value="Driver={Adaptive Server Enterprise};UID=xxxxx;PWD=xxxxx;Database=xxxxxx;Server=xxxxx;Port=4130;" />
<LogFiles value="true" />
</KPlusSynchronizerConsole.Properties.Settings>
</ServiceSettings>
if you look at your spec:
<sectionGroup name="ServiceSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="KPlusSynchronizerConsole.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
it should be clear that you are telling it to expect a section named "KPlusSynchronizerConsole.Properties.Settings" and thus you should have one!
You need to do that same to
<TablesToSynchronize>...

Related

Application configuration file error at runtime

The context :
I have an winform application which is launch by users on the local network (path: \\file-01\appsdeploy$\MyApp )
When I launch the app, it's ok it worked well. But on some other computer it does not work. I have this exception :
An error occurred creating the configuration section handler for
MySection: Request failed.
The declaration of the section in the app.config file is :
<configSections>
<section name="MySection" type="MyGenerator.Config.MySection, MyGenerator"/>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="MySectionGenerator.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
Now the section :
<MySection>
<Addresses>
<add Name="1" Text="ADDRESS ONE"/>
<add Name="2" Text="ADDRESS TWO"/>
<add Name="3" Text="ADDRESS THREE"/>
<add Name="4" Text="ADDRESS FOUR"/>
<add Name="5" Text="ADDRESS FIVE"/>
<add Name="6" Text="ADDRESS SIX"/>
<add Name="7" Text="ADDRESS SEVEN"/>
</Addresses>
</MySection>
NOTE : If I copy the executable and the config file on the local computer, it works fine.
Have you got an idea, a clue... ?
Check with allowExeDefinition=machinetoapplication option.

Enterprise Library 6 - dynamically change log file name

Is it possible to dynamically set log folder and file name in C# which overrides the config value(file name) in the Listeners section of logging configuration?
Tried to follow the below link but it is applicable only for EL 5
Log messages going to previously created log file
This is how i Initialize EL Logging:
IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
LogWriterFactory logWriterFactory = new LogWriterFactory(configurationSource);
Logger.SetLogWriter(logWriterFactory.Create(), false);
ExceptionPolicyFactory factory = new ExceptionPolicyFactory(configurationSource);
ExceptionPolicy.SetExceptionManager(factory.CreateManager());
These are my web.config entries inside the listeners tag:
<add name="RollingFlatFileTraceLog" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="C:\logs\Trace.log" footer=""
formatter="CustomRollingFlatFileLogFormatter"
header="" rollFileExistsBehavior="Overwrite" rollInterval="Day"
rollSizeKB="2048" maxArchivedFiles="52" />
<add name="RollingFlatFileErrorLog" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="C:\logs\Error.log" footer="----------------------------------------"
formatter=" CustomRollingFlatFileLogFormatter "
header="----------------------------------------" rollFileExistsBehavior="Overwrite"
rollInterval="Day" rollSizeKB="2048" maxArchivedFiles="52" />
I use Logger.Write and ExceptionPolicy.HandleException to write to the corresponding trace and error logs.
The best (and easiest!) approach would be to use programmatic configuration to set the filename.
However, you can use a similar approach to modify settings at runtime. Setup the configuration in an external file and use a file configuration source in app/web.config. An external file is necessary to avoid a configuration is read-only exception.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<enterpriseLibrary.ConfigurationSource selectedSource="File-based Configuration Source">
<sources>
<add name="File-based Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
filePath="entlib.config" />
</sources>
</enterpriseLibrary.ConfigurationSource>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
</configuration>
And configure the external file (entlib.config in this case):
<configuration>
<configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<exceptionHandling>
<exceptionPolicies>
<add name="Policy">
<exceptionTypes>
<add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow">
<exceptionHandlers>
<add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
priority="0" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
source="Enterprise Library Logging" formatter="Text Formatter"
log="" machineName="." traceOutputOptions="None" />
<add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="trace.log" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
Extended Properties: {dictionary({key} - {value}{newline})}"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Flat File Trace Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Event Log Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
</configuration>
Use the SerializableConfigurationSource from the blog posting:
public class SerializableConfigurationSource : IConfigurationSource
{
Dictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
public SerializableConfigurationSource()
{
}
public ConfigurationSection GetSection(string sectionName)
{
ConfigurationSection configSection;
if (sections.TryGetValue(sectionName, out configSection))
{
SerializableConfigurationSection section = configSection as SerializableConfigurationSection;
if (section != null)
{
using (StringWriter xml = new StringWriter())
using (XmlWriter xmlwriter = System.Xml.XmlWriter.Create(xml))
{
section.WriteXml(xmlwriter);
xmlwriter.Flush();
MethodInfo methodInfo = section.GetType().GetMethod("DeserializeSection", BindingFlags.NonPublic | BindingFlags.Instance);
methodInfo.Invoke(section, new object[] { XDocument.Parse(xml.ToString()).CreateReader() });
return configSection;
}
}
}
return null;
}
public void Add(string sectionName, ConfigurationSection configurationSection)
{
sections[sectionName] = configurationSection;
}
public void AddSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
{
throw new NotImplementedException();
}
public void Remove(string sectionName)
{
sections.Remove(sectionName);
}
public void RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
{
throw new NotImplementedException();
}
public event EventHandler<ConfigurationSourceChangedEventArgs> SourceChanged;
public void Dispose()
{
}
}
Bootstrap the blocks at startup:
IConfigurationSource configSource = ConfigurationSourceFactory.Create();
var loggingSettings = configSource.GetSection(LoggingSettings.SectionName) as LoggingSettings;
var data = loggingSettings.TraceListeners.First(t => t.Name == "Flat File Trace Listener") as FlatFileTraceListenerData;
// Change the file name
data.FileName = "trace_1.txt";
var loggingXmlConfigSource = new SerializableConfigurationSource();
loggingXmlConfigSource.Add(LoggingSettings.SectionName, loggingSettings);
var logFactory = new LogWriterFactory(loggingXmlConfigSource);
Logger.SetLogWriter(logFactory.Create());
IConfigurationSource config = ConfigurationSourceFactory.Create();
ExceptionPolicyFactory factory = new ExceptionPolicyFactory(config);
ExceptionManager exManager = factory.CreateManager();
ExceptionPolicy.SetExceptionManager(exManager);
// This will log to the file trace_1.txt
ExceptionPolicy.HandleException(new Exception(), "Policy");
As you have mentioned in the post, Setup the configuration in an external file. External file means, can you confirm in which path we have to place the Entlib.config file.

Microsoft.Practices.ServiceLocation.ActivationException was unhandled by user code

I am working on migrating the current ASP.NET application from 2.0 to 4.0 and also trying to migrate the enterprise library to 5.0 from 4.0
I have made all the necessary changes in the configuration file. All the application is working on project mates machine but it is not working on my machine.
Stack Trace of the error I am getting ---
Microsoft.Practices.ServiceLocation.ActivationException was unhandled by user code
HResult=-2146233088
Message=Activation error occured while trying to get instance of type LogWriter, key ""
Source=Microsoft.Practices.ServiceLocation
StackTrace:
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()
at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer()
at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(LogEntry log)
at App.LogEntryHelper.WriteLogEntry(LogEntry entry, String category) in c:\App.Client.WebUI\AppCode\LogEntryHelper.cs:line 252
at App.LogEntryHelper.WriteFacadePerformanceLog(DateTime start, DateTime end) in c:\App.Client.WebUI\AppCode\LogEntryHelper.cs:line 209
at App.Facade.FutureEventFacade.GetFutureEventsParticipant(Int64 participantID) in c:\App.Client.WebUI\Facade\FutureEventFacade.cs:line 92
at App.Facade.ParticipantFacade.GetParticipant(Int64 participantID) in c:\App.Client.WebUI\Facade\ParticipantFacade.cs:line 81
at App.ParticipantPage.Page_Load(Object sender, EventArgs e) in c:\App.Client.WebUI\ParticipantPage.aspx.cs:line 67
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Adapters.ControlAdapter.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: Microsoft.Practices.Unity.ResolutionFailedException
HResult=-2146233088
Message=Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type LogWriter cannot be constructed. You must configure the container to supply this value.
-----------------------------------------------
At the time of the exception, the container was:
Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)
Source=Microsoft.Practices.Unity
TypeRequested=LogWriter
StackTrace:
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)
at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
InnerException: System.InvalidOperationException
HResult=-2146233079
Message=The type LogWriter cannot be constructed. You must configure the container to supply this value.
Source=Microsoft.Practices.Unity
StackTrace:
at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor)
at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey)
at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
InnerException:
Here are the details of configuration file
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="App.Properties.SecuritySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
<section name="App.Properties.ReportingSettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
<section name="App.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
<sectionGroup name="system.web">
<section name="uploadManagement" type="App.WebControls.UploadModule, App.WebControls"/>
</sectionGroup>
<!-- AJAX -->
<!-- End AJAX -->
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add fileName="App.Debug.log" header="----------------------------------------" footer="----------------------------------------" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Debug Flat File TraceListener"/>
<add fileName="App.Client.WebUI.Facade.Performance.log" header="----------------------------------------" footer="----------------------------------------" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Facade Performance Flat File TraceListener"/>
<add fileName="App.Exception.log" rollSizeKB="10000" timeStampPattern="ddd" rollFileExistsBehavior="Overwrite" rollInterval="Day" formatter="Text Formatter" header="----------------------------------------" footer="----------------------------------------" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="Callstack" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Rolling Flat File TraceListener"/>
<add source="AdminTool Web UI" formatter="Text Formatter" log="AdminTool" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="Callstack" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="WebUI EventLog TraceListener"/>
<add fileName="App.SSO.log" header="----------------------------------------" footer="----------------------------------------" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="SSO Flat File TraceListener"/>
</listeners>
<formatters>
<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=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Text Formatter"/>
</formatters>
<logFilters>
<add minimumPriority="0" maximumPriority="3" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.PriorityFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Priority Debug Filter"/>
</logFilters>
<categorySources>
<add switchValue="All" name="Web UI Debug">
<listeners>
<add name="Debug Flat File TraceListener"/>
</listeners>
</add>
<add switchValue="All" name="Web UI Exception">
<listeners>
<add name="Rolling Flat File TraceListener"/>
<add name="WebUI EventLog TraceListener"/>
</listeners>
</add>
<add switchValue="All" name="Web UI Facade Performance">
<listeners>
<add name="Facade Performance Flat File TraceListener"/>
</listeners>
</add>
<add switchValue="All" name="Web UI SSO">
<listeners>
<add name="SSO Flat File TraceListener"/>
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events"/>
<notProcessed switchValue="All" name="Unprocessed Category">
<listeners>
<add name="Debug Flat File TraceListener"/>
<add name="WebUI EventLog TraceListener"/>
<add name="SSO Flat File TraceListener"/>
</listeners>
</notProcessed>
<errors switchValue="All" name="Logging Errors & Warnings"/>
</specialSources>
</loggingConfiguration>
<exceptionHandling>
<exceptionPolicies>
<add name="WebUI Policy">
<exceptionTypes>
<add type="System.DirectoryServices.DirectoryServicesCOMException, System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" postHandlingAction="None" name="DirectoryServicesCOMException"/>
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None" name="Exception">
<exceptionHandlers>
<add logCategory="Web UI Exception" eventId="2000" severity="Error" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" priority="0" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Logging Handler"/>
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
</configuration>
I am able to resolve the issue. I found that I have installed version of ESB 2.0 which was causing the issue. Whenever application is trying to log something IIS used to look into the ESB configuration file instead of web.config file. As soon as I uninstalled the ESB application everything started working.
For me I was opening another configuration file which had the enterpriseLibrary but it was missing from the local app configuration file. I added the following into the local configuration and I got past the error.
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral" requirePermission="true" />
</configSections>

Multiple AppSettings files, is it possible?

I want to create 3 AppSettings config files:
Database.config
Messages.config
Global.config
And after add in my App.config:
<appSettings file="Database.config" />
<appSettings file="Messages.config" />
<appSettings file="Global.config" />
But when I try to access a key that there is in one of three files with the ConfigurationManager, I got the following error:
Configuration system failed to initialize. Sections must only appear once per config file.
I cannot have more than one AppSettings config file?
You can't have more than one appsettings because that's the name of a section. You can add a new section though that uses the same kind of section definition as appsettings. E.g.,
<configuration>
<configSections>
<section name="DatabaseConfig" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
....
<DatabaseConfig>
<add key="Whatever" value="stuff"/>
</DatabaseConfig>
</configuration>
Code for separate file:
Web.config:
<configSections>
<section name="DatabaseConfig" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="MessageConfig" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="GlobalConfig" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<DatabaseConfig configSource="database.config">
</DatabaseConfig>
<MessageConfig configSource="message.config">
</MessageConfig>
<GlobalConfig configSource="global.config">
</GlobalConfig>
database.config:
<DatabaseConfig>
<add key="Name" value="ServerName" />
</DatabaseConfig>
etc...
Can be accessed via code like this:
var databaseConfiguration = (NameValueCollection)ConfigurationManager.GetSection("DatabaseConfig");
string name = databaseConfiguration["Name"];

logging stack trace with logger

I am using Logging Application block with C#.Net 2.0. My code is logging the error information to a flat file. I have set all required configuration in web.config like listeners, formatters and categories, etc as described in msdn and it is working fine.
But the problem is, I cannot put more than 50 characters in le.Message property. In my case, the stack trace is more than 500 charactors long which I want to log into the flat file when error occurs.
Is there any limit on number of charactors we can put inside Message Property of LogEntry object? or is there any other way to log the stack trace into logger flat file?
Here is the simple code.
LogEntry le = new LogEntry();
le.Categories.Add("ErrorsToEventLog");
le.Categories.Add("ErrorsToLogFile");
le.Title = "Error message";
le.TimeStamp = System.DateTime.Now;
le.Severity = System.Diagnostics.TraceEventType.Error;
le.Message = "<text of error's stack trace>";
Logger.write(le);
configuration settings
<configSections>
<section name="loggingConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=null" />
<section name="dataConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=null" />
</configSections>
Here is the formatter I used,
<formatters>
<add template="Timestamp: {timestamp} Message: {message}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0,
Culture=neutral, PublicKeyToken=null" name="Text Formatter" />
</formatters>
And here is the listener,
<add fileName="Logs/ErrorLog_{Date}.log"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.
CustomTraceListenerData,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=null" traceOutputOptions="None"
type="EnterpriseLibrary.Logging.Extensions.RollingFlatFileTraceListener,
EnterpriseLibrary.Logging.Extensions, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" name="Custom TraceListener" initializeData="" />
Categories
<categorySources>
<add switchValue="All" name="ErrorsToEventLog">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</add>
<add switchValue="All" name="ErrorsToLogFile">
<listeners>
<add name="Custom TraceListener" />
</listeners>
</add>
</categorySources>
To my knowledge, there is no such limit for log message. How do you set the stack trace to the message?
Assuming your analysis is correct (it isn't convenient for me to double-check right now), have you considered creating a subclass for LogEntry that doesn't have the limits that you're running up against?

Categories

Resources