Tridion Search is not working - tridion

During upgrade from Tridion 5.3 SP1 to Tridion 2011 SP1 we have configured search service as instructed in the Installation manual.
When we try to search ".aspx" word in the entire content it is giving error.
(80040356) The remote server returned an error: (404) Not Found.Unable to get the list of search results.Error occured while processing the request: Not Found.
System.Net.HttpWebRequest.GetResponse()
Tridion.ContentManager.Search.SolrClient.ProcessResponse(HttpWebRequest,Boolean,Boolean,String&)
Tridion.ContentManager.Search.SolrClient.Post(String,String,String&)
Tridion.ContentManager.Search.SolrClient.Query(String,Int32,Nullable`1,String&)
Tridion.ContentManager.Search.SearchQueryEngine.GetSearchResultsFromSolr(SearchQueryData,Int32,Nullable`1)
Tridion.ContentManager.Search.SearchQueryEngine.GetSearchResultsFromSolr(SearchQueryData,Int32,Nullable`1)
Tridion.ContentManager.Search.SearchQueryEngine.GetSearchResults(SearchQueryData,Int32,Int32)
Tridion.ContentManager.Search.ComWrapper.SearchQueryEngineFacade.GetSearchResults(Int32,Int32)
SearchBLST.GetListData
SearchBLST.GetSearchResults
SearchBLST.GetSearchResultsEx
Search.GetSearchResultsEx
How can we troubleshoot the issue?
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=349a39f202fa9b53"/>
<section name="tridionConfigSections" type="Tridion.Configuration.ConfigurationSections, Tridion.Common, Version=6.1.0.25, Culture=neutral, PublicKeyToken=349a39f202fa9b53"/>
<section name="tridion.common" type="Tridion.Configuration.CommonSettings, Tridion.Common, Version=6.1.0.25, Culture=neutral, PublicKeyToken=349a39f202fa9b53"/>
<section name="solrHost" type="Tridion.ContentManager.Search.SearchHost.Configuration.SolrHostConfiguration, TcmSearchHost, Version=6.1.0.996, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b"/>
</configSections>
<configProtectedData>
<providers>
<add name="TridionRsaProtectedConfigurationProvider" keyContainerName="TridionRsaKeyContainer" useMachineContainer="true" description="Uses RsaCryptoServiceProvider to encrypt and decrypt" type="System.Configuration.RsaProtectedConfigurationProvider,
System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</configProtectedData>
<tridionConfigSections>
<sections>
<clear/>
<add/>
<add name="loggingConfiguration"/>
</sections>
</tridionConfigSections>
<tridion.common>
<tracing enabled="false">
<parameterValueTruncation default="50">
<parameterTypes>
<clear/>
<!-- Do not remove or change the settings for type System.Data.IDataRecord -->
<add type="System.Data.IDataRecord" assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" maxLength="0"/>
</parameterTypes>
</parameterValueTruncation>
</tracing>
</tridion.common>
<loggingConfiguration name="Logging Application Block" tracingEnabled="false" defaultCategory="General" logWarningsWhenNoCategoriesMatch="false">
<listeners>
<add name="Tridion Console Trace Listener" formatter="Trace Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=349a39f202fa9b53" traceOutputOptions="None" type="Tridion.Logging.TridionConsoleTraceListener, Tridion.Logging, Version=6.1.0.25, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b" initializeData=""/>
<add name="Tridion Debug Trace Listener" formatter="Trace Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=349a39f202fa9b53" traceOutputOptions="None" type="Tridion.Logging.TridionDebugTraceListener, Tridion.Logging, Version=6.1.0.25, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b" initializeData=""/>
<add name="Tridion Event Log" EventLog="Tridion" formatter="Event Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=349a39f202fa9b53" traceOutputOptions="None" type="Tridion.Logging.TridionEventLogTraceListener, Tridion.Logging, Version=6.1.0.25, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b" initializeData=""/>
<add name="Log File" formatter="Trace Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=349a39f202fa9b53" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=349a39f202fa9b53" fileName="D:\Tridion\log\TcmSearchHost.log"/>
<add name="Trace File" formatter="Trace Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=349a39f202fa9b53" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=349a39f202fa9b53" fileName="D:\Tridion\log\TcmSearchHost.trace.log"/>
</listeners>
<formatters>
<add name="Log Text Formatter" template="{timestamp} <{win32ThreadId}> {message}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=349a39f202fa9b53"/>
<add name="Trace Text Formatter" template="{timestamp(HH:mm:ss.ffff)} <{win32ThreadId}> {message}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=349a39f202fa9b53"/>
<add name="Event Text Formatter" template="{message}
Component: {keyvalue(component)}
Errorcode: {keyvalue(errorcode)}
User: {keyvalue(username)}
{keyvalue(stacktrace)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=349a39f202fa9b53"/>
</formatters>
<categorySources>
<add switchValue="All" name="Tridion.Logging.LoggingCategory.Tracing">
<listeners>
<add name="Trace File"/>
</listeners>
</add>
<add switchValue="All" name="Tridion.ContentManager.Search.SearchHost.LogCategory">
<listeners>
<!--add name="Tridion Console Trace Listener"/-->
</listeners>
</add>
<add switchValue="All" name="General"/>
</categorySources>
<specialSources>
<allEvents switchValue="Information" name="All Events">
<listeners>
<add name="Tridion Event Log"/>
</listeners>
</allEvents>
<notProcessed switchValue="All" name="Unprocessed Category"/>
<errors switchValue="All" name="Logging Errors & Warnings"/>
</specialSources>
</loggingConfiguration>
<!--To configure this Solr Instance as Master enable this solrHost xml node and disbale the other solrHost xml node-->
<!--<solrHost heartbeatTimeout="300" solrHome="%TRIDION_CM_HOME%\Libraries\solr-home" solrDataDir="%TRIDION_CM_HOME%\Search\solr-data" solrLogDir="%TRIDION_CM_HOME%\Log" jvmOptions="-Xmx768m -Xms768m -XX:MaxDirectMemorySize=1024m -Dfile.encoding=UTF-8 -Djava.security.auth.login.config=conf/jaaslogin.conf -Djava.security.auth.policy=conf/jaas.policy -Dlog4j.configuration=file:conf\log4j.properties -Djava.class.path=start.jar;lib\* -Duser.language=en -Duser.country=US -Denable.master=true" jvmFilePath="">-->
<!--To configure this Solr Instance as slave enable this solrHost xml node and disbale the other solrHost xml node. Set the -Dmaster.url, -Dmaster.authUser="MASTER_SOLR_INSTANCE_USER_NAME" and -Dmaster.authPassword-->
<!--<solrHost heartbeatTimeout="300" solrHome="%TRIDION_CM_HOME%\Libraries\solr-home" solrDataDir="%TRIDION_CM_HOME%\Search\solr-data" solrLogDir="%TRIDION_CM_HOME%\Log" jvmOptions="-Xmx768m -Xms768m -XX:MaxDirectMemorySize=1024m -Dfile.encoding=UTF-8 -Djava.security.auth.login.config=conf/jaaslogin.conf -Djava.security.auth.policy=conf/jaas.policy -Dlog4j.configuration=file:conf\log4j.properties -Djava.class.path=start.jar;lib\* -Duser.language=en -Duser.country=US -Denable.slave=true -Dmaster.url=MASTER_SOLR_INSTANCE_URL -Dmaster.authUser=MASTER_SOLR_INSTANCE_USER_NAME -Dmaster.authPassword=MASTER_SOLR_INSTANCE_PASSWORD" jvmFilePath="">-->
<solrHost heartbeatTimeout="300" jvmOptions="-Xmx768m -Xms768m -XX:MaxDirectMemorySize=1024m -Dfile.encoding=UTF-8 -Djava.security.auth.login.config=conf/jaaslogin.conf -Djava.security.auth.policy=conf/jaas.policy -Dlog4j.configuration=file:conf\log4j.properties -Djava.class.path=start.jar;lib\* -Duser.language=en -Duser.country=US" jvmFilePath="" solrHome="D:\Tridion\solr-home\" solrDataDir="D:\Tridion\solr-data\" solrLogDir="D:\Tridion\log\">
<jetty port="8983" stopControlKey="#SdlTridionJettySolrKey#" stopControlPort="8079" mainClassName="org/mortbay/start/Main" jettyConfigurationArguments="conf\jetty-jmx.xml conf\jetty.xml conf\jetty-logging.xml" home="D:\Tridion\solr-jetty\" tempDir="C:\Windows\TEMP\" logDirectory="D:\Tridion\log\"/>
</solrHost>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
<runtime>
<!--Enable Server GC mode for better performance in CLR 4.0. Note that this may lead to memory issues in CLR 2.0.-->
<gcServer enabled="true"/>
</runtime>
</configuration>

To troubleshoot the Search, first things I would try is to search with different search terms and see if they all return the same result (an error in your case).
Next is to check if the Tridion Content Manager Search Host service and the Tridion Content Manager Search Indexer service are running. If they are, see if restarting them makes any change to the situation.
When my Tridion Content Manager Search Host service is stopped, I get a different error, indicating the connection can't be established. So my thoughts would go out to a configuration error (the 404 mentioned in there makes me wonder if SOLR did install correctly). Check the settings in your MMC snap-in, and also check (like #robrtc mentioned) if you can run the reindex as described in the upgrade manual

Related

Unrecognized configuration section system.identityModel

I keep getting this error when building:
Unrecognized configuration section system.identityModel
I have added the following to my config:
<system.identityModel>
<identityConfiguration>
<audienceUris>
<add value="TEST"/>
</audienceUris>
<issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<trustedIssuers>
<add thumbprint="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234" name="YourSTSName"/>
</trustedIssuers>
</issuerNameRegistry>
<certificateValidation certificateValidationMode="None"/>
</identityConfiguration>
</system.identityModel>
I am using .Net 4.6
You forgot this entry in configSections...
<configSections>
<!--WIF sections -->
<section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</configSections>

Creating a rolling flat log file using Enterprise library

In my web application I am trying to create a log file for logging errors and exceptions, but when I run my application, log file is not getting created in my solution folder or in bin folder.
I used the following code. Please help me I am stuck up with this problem, thank you in advance.
namespaces used
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
.cs file
public int GetdeskKMasterRecordsCount(string CircleId, string StoreId)
{
try
{
throw new Exception("this is normal exception");
}
catch (Exception ex)
{
BindLog(ex);
return 0;
}
}
public static void BindLog(Exception ex)
{
if (ex == null) return;
Logger.Write(LogInformation(1, DateTime.Now, ex.Message, " "));
}
public static LogEntry LogInformation(int eventId, DateTime timeStamp, string message, string documentName)
{
LogEntry logEntryObject = new LogEntry();
logEntryObject.EventId = eventId;
logEntryObject.Title = documentName;
logEntryObject.TimeStamp = timeStamp;
logEntryObject.MachineName = System.Environment.MachineName;
logEntryObject.Message = message;
logEntryObject.Categories.Add("Exception");
return logEntryObject;
}
Web Config file
<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="recordingWindowGroup" type="Vodafone.DMS.BAL.WindowConfigurationHandler, Vodafone.DMS.BAL"/>
<section name="defaultParamGroup" type="Vodafone.DMS.BAL.DefaultParamConfiguration, Vodafone.DMS.BAL"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add name="Rolling Flat File Trace Listener"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="Vodafone.DMS.log.exclude" footer="---------------------------" formatter="Text Formatter" header="---------------------------" rollFileExistsBehavior="Increment"
rollSizeKB="10" timeStampPattern="yyyy-MM-dd hh:mm:ss" maxArchivedFiles="7" traceOutputOptions="Timestamp, Callstack" filter="All"/>
</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}
"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Text Formatter"/>
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Rolling Flat File Trace Listener"/>
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events">
<listeners>
<add name="Rolling Flat File Trace Listener"/>
</listeners>
</allEvents>
<notProcessed switchValue="All" name="Unprocessed Category">
<listeners>
<add name="Rolling Flat File Trace Listener"/>
</listeners>
</notProcessed>
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Rolling Flat File Trace Listener"/>
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
For enterprise library version 5.0 and above, Microsoft has released an enterprise library configuration tool that allows you to change the configurations visually in the configuration file. You can also install this tool from NuGet and that can be accessed from inside the visual studio Tools >> Library Package Manager >> Manage NuGet Packages for solution and add the appropriate EntLib Application Block. You can find guide from here.
Using that tool I have generated a configuration file which is as follows:
Place this in Web.Config or App.Config file
<loggingConfiguration name="loggingConfiguration" tracingEnabled="true"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="RollingFlatFile.log"
footer="---------------------------" formatter="Text Formatter"
header="---------------------------" rollFileExistsBehavior="Increment"
rollInterval="Week" rollSizeKB="20000" timeStampPattern="yyyy-MM-dd hh:mm:ss"
maxArchivedFiles="7" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack"
filter="All" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
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}
"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</allEvents>
<notProcessed switchValue="All" name="Unprocessed Category">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</notProcessed>
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
I would recommend that instead of generating the log file inside the bin directory of the application you should specify a physical location by changing the value of the fileName="RollingFlatFile.log" to something like fileName="c:\logs\RollingFlatFile.log"
You need to set a category on your LogEntry to match a category source in your configuration file ('General' in the configuration you posted). I would also suggest looking at the Exception Handling Application Block if you are planning to log exceptions, instead of writing the code to handle creating a LogEntry yourself.
IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
LogWriterFactory logWriterFactory = new LogWriterFactory(configurationSource);
Logger.SetLogWriter(logWriterFactory.Create(), false);
Logger.Write("btnStartProcess_Click");
Logger.Reset();

Programmatically switch on to Trace Listeners in Enterprise Library

I have enabled two trace listeners using Enterprise Library to log into Event Log and To a Log File.
Is it possible to choose to log up on to only one log at any point of time programmatically(For example I want to log to Event log some times and to Log file some times).
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
source="Enterpriselibrary" formatter="Text Formatter" log="TestLog"
machineName="." traceOutputOptions="None" />
<add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="C:\AER\test.log" formatter="Text Formatter" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.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="Event Log Listener" />
<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>
Sure, just create separate categories and associate individual trace listeners with each category. Then, in your code, you just specify the category you want a LogEntry to be logged through. Like so:
Define your categories:
<categorySources>
<add switchValue="All" name="Category">
<listeners>
<add name="Event Log Listener" />
</listeners>
</add>
<add switchValue="All" name="AnotherCategory">
<listeners>
<add name="Flat File Trace Listener" />
</listeners>
</add>
</categorySources>
and then direct your log entries programmatically:
LogWriter.Write("Log entry through a specific Category to the Event Log", "Category");
LogWriter.Write("Log entry through another Category to a file", "AnotherCategory");

Write to multiple files Enterprise Library Logger

Is it possible using Enterprise Library Logger to log to multiple files grouped by date ? For example Trace-08-22-2011.log, Trace-08-23-2011.log.
Yes, but not with the TraceListeners that ship with Enterprise-Library. What you need is a custom TraceListener or at least TraceListenerData which is used indirectly as a trace listener factory (GetCreationExpression).
The easiers way to do what you've described is to inherit from RollingFlatFileTraceListenerData and overrice GetCreationExpression. It has this.FileName protected field which can be set to whatever you want. For example you could resolve your custom tokens (timestamp)
/// <summary>
/// Returns a lambda expression that represents the creation of the trace listener described by this
/// configuration object.
/// </summary>
/// <returns>A lambda expression to create a trace listener.</returns>
protected override Expression<Func<TraceListener>> GetCreationExpression()
{
// Resolve tokens in FileName
string fileName = ResolveTokens(this.FileName);
return
() =>
new RollingFlatFileTraceListener(
fileName,
this.Header,
this.Footer,
Container.ResolvedIfNotNull<ILogFormatter>(this.Formatter),
this.RollSizeKB,
this.TimeStampPattern,
this.RollFileExistsBehavior,
this.RollInterval,
this.MaxArchivedFiles);
}
And your configuration:
<add name="All Activities Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Sample.CustomFlatFileTraceListenerData, Sample"
fileName="%TEMP%\{timestamp}.log"
footer="" formatter="Detail Text Formatter" rollFileExistsBehavior="Overwrite"
rollInterval="Day" timeStampPattern="yyyy-MM-dd" maxArchivedFiles="10" />
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<!--Flat File Trace Listener-->
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="Default Category" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add source="Enterprise Library Logging" formatter="Text Formatter"
log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Formatted EventLog TraceListener" />
<add fileName="D:\Works\GPIH\GPIAgent\Web\Log\Logger.log"
formatter="One Line Formatter" rollFileExistsBehavior="Increment"
rollInterval="Midnight" rollSizeKB="10000" timeStampPattern="yyyy-MM-dd"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Rolling Flat File" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
Category: {category}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Text Formatter" />
<add 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}
)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="One Line Formatter" />
</formatters>
<logFilters>
<add name="LogEnabled Filter"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
enabled="true" />
</logFilters>
<categorySources>
<add switchValue="Warning" name="Default Category">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events">
<listeners>
<add name="Rolling Flat File" />
</listeners>
</allEvents>
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>

Implementing Log file using Enterprise Library in asp.net

I m using Microsoft Enterprise Library 3.1 for Exception Handling in asp.net, the erors are stored in Event Viewer of the system .
Instead of Event Viewer I need to store these errors in a log File using Enterprise Library.
Dear 2:30, You paste the following code inside configuration section at app.config or web.config file
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="Tracing" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add fileName="AppLog.log" rollSizeKB="1024" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="None" formatter="Text Formatter" header="" footer="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="LogicalOperationStack" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" name="AppLog" />
<add fileName="Exception.log" rollSizeKB="1024" timeStampPattern="MM-dd-yyyy" rollFileExistsBehavior="Increment" rollInterval="None" formatter="Text Formatter" header="" footer="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="Callstack" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" name="Exception" />
<add fileName="trace.log" rollSizeKB="1024" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="Month" formatter="Text Formatter" header="----------------------------------------" footer="----------------------------------------" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" name="Trace" />
</listeners>
<formatters>
<add template="{timestamp} : {message}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="AppLog">
<listeners>
<add name="AppLog" />
</listeners>
</add>
<add switchValue="Verbose" name="ExceptionHandling">
<listeners>
<add name="Exception" />
</listeners>
</add>
<add switchValue="Information" name="Tracing">
<listeners>
<add name="Trace" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="Off" name="Logging Errors & Warnings" />
</specialSources>
</loggingConfiguration>
Application log can be logged into applog.log file using following statement
Logger.Write("Application Started", "AppLog");
Application exception can be logged into Exception.log file using following statement
Logger.Write("Error: Invalid information you passed", "ExceptionHandling");
Note: You can find the Logger class in Microsoft.Practices.EnterpriseLibrary.Logging;
AppLog.log and Exception.log file will be created in bin folder automatically.
In Entlib a Category is connected to a listener, then a listener determines where the log information is written. To log to a file use a Flat File Listener.
http://msdn.microsoft.com/en-us/library/cc309257.aspx
<listeners>
<add fileName="..\..\logfiles\BusinessActivity.log" rollSizeKB="10000" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="None" formatter="Text Formatter" header="----------------------------------------" footer="----------------------------------------" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Rolling Flat File BusinessActivity Listener" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp(local)}
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=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="BusinessActivityLog">
<listeners>
<add name="Rolling Flat File BusinessActivity Listener" />
</listeners>
</categorySources>
You need to read about Flat File Trace Listener/Rolling Flat File Trace Listener and Trace Listeners in general.

Resources