clement
clement

Reputation: 4266

The name something does not exists in the current context with static class

I have a Logger that I've pout into a static class.

I want to be albe to call the (static) methods of this class in all my app layers.

Here, My business layer (portable class), I use normal classes with static methods but I can't call my Logger, the name LOGGER does not exists in the current context.

I have a reference to the Logger project, but there is a warning icon on the reference. There is no paht on the properties of the reference, but I really added the reference by clicking on Project then the project that contains the logger.

Call to Logging:

public class AnomalyBL
    {
        private static Container<IList<Anomaly>> MyMethod()
        {
            try
            {
                something
            }
            catch (Exception ex)
            {
                string errorMsg = string.Format("text ({0})", ex.Message);
                Logger.MyLogger.LogError(ex, errorMsg);
            }
            return container;
        }
}

Logger:

namespace Logger{
public static class MyLogger
    {

        public static bool LogError(Exception ex, string message = "")
        {
            try
            {
                GetLogger().Log(LogLevel.Error, ex, message);
            }
            catch (Exception exception)
            {
                return false;
            }
            return true;
        }
}
}

Thanks in advance

Upvotes: 1

Views: 4141

Answers (1)

Alireza
Alireza

Reputation: 5513

There are several reasons why references might not work and have that warning icon: First try to remove the reference, then add it again: Say you have project A that should refer to project B which contains Logger. In solution explorer, in project A right click on References -> add reference -> solution -> Project B

If the new reference is still showing the warning, then there should be a problem like: The .net version in project B is Higher than A, Or the platforms do not match, for instance project B targets .Net framework and A is a silverlight project. In the errors window, click on warnings icon to see the warnings, there should be one which explains the reason why project B cannot be referenced from A

Upvotes: 2

Related Questions