简体   繁体   中英

Inaccessible due to protection level in C#

I have references object which contains abstract LoggerFile class. I am trying to access it. But it is showing inaccessible due to protection level. Please anyone help me to understand it.

abstract class LoggerFile
{
     private static String logFile = null;

        /// <summary>
        ///     Logfile Property
        /// </summary>
        public static string LogFile { get => logFile; set => logFile = value; }

        /// <summary>
        ///     Set logFile
        /// </summary>
        /// <param name="logFile">The absolute path to file for writting logs</param>
        public static void SetLogFile(String logFile)
        {
            LogFile = LogFile ?? logFile;
            if (!File.Exists(LogFile))
            {
                File.Create(LogFile).Close();
            }
            }
}
}

I am calling this in another class.

using DriverAutomation.Loggin[enter image description here][1]g;
    public class Devcon
    {
        private static Devcon devcon = null;

        private readonly String devconEXE;
    private readonly String devconPath;
    private readonly String devconExeName;
    private readonly Logger logger;

    /// <summary>
    ///     DevconStatus Property for devcon status outcome backup
    /// </summary>
    public readonly String devconStatus;

    /// <summary>
    ///     Initializes the Devcon Singleton Instance
    /// </summary>
    private Devcon()
    {
        devcon = this;
        logger = Logger.GetLogger(GetType().Name, LoggerFile.LogFile);
        devconExeName = "devcon.exe";
        devconEXE = Path.Combine(Directory.GetCurrentDirectory(), devconExeName);
}
}

This is working within created solution. But using reference object it is showing error. Please find image.

Declare your class as public and non-Abstract and I think it will solve your problem.

public class LoggerFile

By the way, why is it even Abstract . If you only have some static members in it, maybe you should just turn it to static itself.

Though in most logger implementations, it makes sense to follow the singleton pattern (one of the few cases)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM