Errors after upgraded to EntLib 1.0 to 5.0

Topics: Logging Application Block, Security Application Block
Nov 22, 2010 at 8:24 AM
Edited Nov 22, 2010 at 8:25 AM

Hi all,

The following errors i am getting after upgraded my application from EntLib 1.0 to EntLib5.0.Please help me .

 

1.   The type or namespace name 'LoggingConfigurationView' could not be found (are you missing a using directive or an assembly reference?)

2.  The type or namespace name 'EmailSinkData' could not be found (are you missing a using directive or an assembly reference?)   

3. The type or namespace name 'Distributor' does not exist in the namespace 'Microsoft.Practices.EnterpriseLibrary.Logging' (are you missing an assembly reference?)   

Thanks in Advance,

 

Nov 22, 2010 at 8:40 AM

This isn't a very straightforward process.  First, the ConfigurationView classes have been removed from EntLib 5.0.  Could you tell me what specific functionality you require which makes you use this in your code?  I could probably suggest a workaround. 

Next, sorry but I didn't get to use the EmailSinkData class so I'm not familiar with it and I have no source code of it.  Again, I have to ask you what is its function.

On the third item, does the Distributor class functions related to the Distributor Service?  If yes, classes relating to that functionality can be found in the Microsoft.Practices.EnterpriseLibrary.Logging.MsmqDistributor assembly.  But still, there's no Distributor class in the 5.0 version of EntLib.

And lastly, you would need to modify your config file since the System.Configuration namespace has been heavily modified since .NET Framework 2.0.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 22, 2010 at 8:55 AM
Hi Sarah Urmeneta ,


Thanks your valuable response for this thread (http://entlib.codeplex.com/Thread/View.aspx?ThreadId=235552).Please find the attached image file and suggest me possible workaround .For showing the name space of " EmailsinkData "
I have added EntLib 1.0 Logging dll and taken snapshot .

Thank you ,
Srinivas.K


From: [email removed]
To: [email removed]
Date: Mon, 22 Nov 2010 01:40:50 -0800
Subject: Re: Errors after upgraded to EntLib 1.0 to 5.0 [entlib:235552]

From: AvanadeSupport
This isn't a very straightforward process. First, the ConfigurationView classes have been removed from EntLib 5.0. Could you tell me what specific functionality you require which makes you use this in your code? I could probably suggest a workaround.
Next, sorry but I didn't get to use the EmailSinkData class so I'm not familiar with it and I have no source code of it. Again, I have to ask you what is its function.
On the third item, does the Distributor class functions related to the Distributor Service? If yes, classes relating to that functionality can be found in the Microsoft.Practices.EnterpriseLibrary.Logging.MsmqDistributor assembly. But still, there's no Distributor class in the 5.0 version of EntLib.
And lastly, you would need to modify your config file since the System.Configuration namespace has been heavily modified since .NET Framework 2.0.

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com
Read the full discussion online.
To add a post to this discussion, reply to this email (entlib@discussions.codeplex.com@discussions.codeplex.com)
To start a new discussion for this project, email entlib@discussions.codeplex.com@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Nov 22, 2010 at 9:09 AM

Please send it to entlib.support@avanade.com in .zip format. 

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 22, 2010 at 9:14 AM

Hi Sarah Urmeneta,

Thanks your valuable response  .Please see the below code and tell me possible work around.

 

if (!Page.IsPostBack)
			{
				LoggingConfigurationView cView = new LoggingConfigurationView(ConfigurationManager.GetCurrentContext());
				EmailSinkData emailSink = (EmailSinkData)cView.GetSinkData("Exception Email Sink");
				logEmailDestination.Text = emailSink.ToAddress ;
				logEmailFrom.Text = emailSink.FromAddress ;
			}



Thank you ,

Nov 22, 2010 at 9:23 AM
Edited Nov 22, 2010 at 9:27 AM

I see, so the EmailSinkData is actually the configuration class for an email trace listener? And you simply want to retrieve the value of the ToAddress and FromAddress property? If yes, then here's the equivalent API in EntLib 5.

IConfigurationSource configSource = ConfigurationSourceFactory.Create();
LoggingSettings loggingSettings = (LoggingSettings)configSource.GetSection(LoggingSettings.SectionName);
EmailTraceListenerData emailTraceListenerData = (EmailTraceListenerData)loggingSettings.TraceListeners.Get("Exception Email Sink")
logEmailDestination.Text = emailTraceListenerData.ToAddress;
logEmailFrom.Text = emailSink.FromAddress;

The first line of code creates an instance of IConfigurationSource representing your default configuration file.  The second line of code retrieves a LoggingSettings instance from it which represents the loggingConfiguration section.

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 8, 2011 at 10:05 PM

Hi,

I have a project that I am trying to upgrade from .net 1.1 to 2.0 where it is using LoggingConfigurationView in ver 1.1.

I found that the functionality of Microsoft.Practices.EnterpriseLibrary.Logging.Sinks in 1.1 has been replaced by tracelisteners class in system.diagnostics class in 2.0.

when i made that switch i get 2 errors:

The type or namespace name 'LoggingConfigurationView' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'ConfigurationView' could not be found (are you missing a using directive or an assembly reference?)

Any ideas?

Thanks,

Ricky

 

using System;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;
//using Microsoft.Practices.EnterpriseLibrary.Logging.Sinks;
using Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners;
using System.Diagnostics;
using FOX.FBC.Logging.Sinks.Database.Configuration;
 

namespace FOX.FBC.Logging.Sinks.Database
{
    /// <summary>
    /// Represents a database logging sink.  Executes a stored procedure for each log entry.
    /// Database and stored procedure are retrieved from the configuration settings.
    /// </summary>
    //rb public class DatabaseSink : LogSink
    public class DatabaseSink : TraceListener
    {

        //rb private DefaultLogDestination defaultSink;
        private LoggingConfigurationView loggingConfigurationView;
       
        /// <summary>
        /// Default constructor
        /// </summary>
        public DatabaseSink()
        {
            //rb defaultSink = new DefaultLogDestination();
        }

        /// <summary>
        /// <para>
        /// Initializes the provider with its name and any attributes associated with the provider.
        /// </para>
        /// </summary> 
        /// <param name="configurationView">A <see cref="LoggingConfigurationView"></see> object.</param>     
        public override void Initialize(ConfigurationView configurationView)
        {
            ArgumentValidation.CheckForNullReference(configurationView, "configurationView");
            ArgumentValidation.CheckExpectedType(configurationView, typeof (LoggingConfigurationView));

            this.loggingConfigurationView = (LoggingConfigurationView) configurationView;
        }


//        public DatabaseSink(DatabaseSinkData providerData, ConfigurationContext context)
//        {
//            Initialize(providerData, context);
//        }
//
//        public void Initialize(ProviderData providerData, ConfigurationContext context)
//        {
//            this.sinkParameters = (DatabaseSinkData)providerData;
//            this.context = context;
//        }


        /// <summary>
        /// Execute a stored procedure to record the log entry.
        /// </summary>
        /// <param name="logEntry"><see cref="LogEntry"></see> to send to database</param>
        protected override void SendMessageCore(LogEntry logEntry)
        {
            if (ValidateParameters(logEntry))
            {
                try
                {
                    ExecuteStoredProcedure(logEntry);
                }
                catch (Exception e)
                {
                    logEntry.AddErrorMessage(SR.SinkFailure(e.ToString()));
                    throw;
                }
                catch
                {
                    logEntry.AddErrorMessage(SR.SinkFailure(SR.UnknownError));
                }
            }
        }

        private bool ValidateParameters(LogEntry logEntry)
        {
            bool valid = true;
            DatabaseSinkData databaseSinkData = loggingConfigurationView.GetSinkData(ConfigurationName) as DatabaseSinkData;
            if (databaseSinkData == null)
            {
                valid = false;
            }

            if (databaseSinkData.DatabaseInstanceName == null ||
                databaseSinkData.DatabaseInstanceName.Length == 0)
            {
                valid = false;
            }

            if (databaseSinkData.StoredProcName == null ||
                databaseSinkData.StoredProcName.Length == 0)
            {
                valid = false;
            }

            if (!valid)
            {
                logEntry.AddErrorMessage(SR.DatabaseSinkMissingParameters);
                //rb this.defaultSink.SendMessage(logEntry);
                //rb
                Logger.Write(logEntry);
            }

            return valid;
        }

        private void ExecuteStoredProcedure(LogEntry logEntry)
        {
            DatabaseSinkData databaseSinkData = loggingConfigurationView.GetSinkData(ConfigurationName) as DatabaseSinkData;
            DatabaseProviderFactory factory = new DatabaseProviderFactory(loggingConfigurationView.ConfigurationContext);
            Microsoft.Practices.EnterpriseLibrary.Data.Database db = factory.CreateDatabase(databaseSinkData.DatabaseInstanceName);
            DBCommandWrapper cmd = db.GetStoredProcCommandWrapper(databaseSinkData.StoredProcName);

            cmd.AddInParameter("@p_event_id", DbType.Int32, logEntry.EventId);
            cmd.AddInParameter("@p_category", DbType.String, logEntry.Category);
            cmd.AddInParameter("@p_priority", DbType.Int32, logEntry.Priority);
            cmd.AddInParameter("@p_severity", DbType.String, logEntry.Severity.ToString());
            cmd.AddInParameter("@p_title", DbType.String, logEntry.Title);
            cmd.AddInParameter("@p_timestamp", DbType.DateTime, logEntry.TimeStamp);
            cmd.AddInParameter("@p_machine_name", DbType.String, logEntry.MachineName);
            cmd.AddInParameter("@p_app_domain_name", DbType.String, logEntry.AppDomainName);
            cmd.AddInParameter("@p_process_id", DbType.String, logEntry.ProcessId);
            cmd.AddInParameter("@p_process_name", DbType.String, logEntry.ProcessName);
            cmd.AddInParameter("@p_thread_name", DbType.String, logEntry.ManagedThreadName);
            cmd.AddInParameter("@p_thread_id", DbType.String, logEntry.Win32ThreadId);
            cmd.AddInParameter("@p_message", DbType.String, logEntry.Message);
           
            db.ExecuteNonQuery(cmd);
        }
    }
}

Mar 9, 2011 at 12:03 AM

You would need to replace it with the LoggingSettings class.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com