/// <summary>
        /// log using info log level
        /// </summary>
        /// <param name="ex"> the exception to be logged</param>
        /// <param name="logParaemtersArr">array of objects to log their values for custom message user must override toSting() method</param>
        /// <param name="messageFormat">format of the message to be logged</param>
        /// <param name="messageParameters">the parameters to fill the message placeholders</param>
        public static void LogInfo(string messageFormat, object[] messageParameters = null
                                   , Exception ex = null, object[] logObjectsArr = null
                                   , [CallerMemberName] string callerInfo = "")
        {
            string finalMessage = CreateLogMessage(logObjectsArr, messageFormat, callerInfo, messageParameters);

            if (ex == null)
            {
                CurrentLogger.Info(finalMessage);
            }
            else
            {
                CurrentLogger.Info(ex, finalMessage);
            }
        }
Exemple #2
0
 public static void Info(string msg)
 {
     CurrentLogger.Info(msg);
 }
        static void Init()
        {
            lock (initializationLocker)
            {
                if (_currentLogger == null)
                {
                    if (string.IsNullOrEmpty(AbsoluteConfigurationFilePath))
                    {
                        throw new LoggerExcetion(string.Format("{0}:Configuration file name is not set in application configuration", LOCAL_MODULE_NAME),
                                                 LoggerFailureType.ConfigFailure);
                    }
                    if (!File.Exists(AbsoluteConfigurationFilePath))
                    {
                        throw new LoggerExcetion(string.Format("{0}:Configuration file named {1} does not exist", LOCAL_MODULE_NAME, AbsoluteConfigurationFilePath),
                                                 LoggerFailureType.ConfigFailure);
                    }
                    try
                    {
                        LogManager.ThrowConfigExceptions = true;
                        LogManager.Configuration         = new NLog.Config.XmlLoggingConfiguration(AbsoluteConfigurationFilePath, false);

                        _currentLogger = LogManager.GetCurrentClassLogger();

                        string rootpath = LogManager.Configuration.Variables[ROOTPATH_VAR_NAME] == null ? null : LogManager.Configuration.Variables[ROOTPATH_VAR_NAME].Text;

                        if (string.IsNullOrEmpty(rootpath))
                        {
                            throw new LoggerExcetion(string.Format("{0}:Root Directory path variable is null or empty", LOCAL_MODULE_NAME),
                                                     LoggerFailureType.ConfigFailure);
                        }

                        if (!Directory.Exists(rootpath))
                        {
                            try
                            {
                                Directory.CreateDirectory(rootpath);
                            }
                            catch (Exception ex)
                            {
                                throw new LoggerExcetion(string.Format("{0}:Failed to create root logging folder with path {1}", LOCAL_MODULE_NAME, rootpath), ex,
                                                         LoggerFailureType.ConfigFailure);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new LoggerExcetion(string.Format("{0}:failed to initialize log configuration from file {1}", LOCAL_MODULE_NAME, AbsoluteConfigurationFilePath), ex,
                                                 LoggerFailureType.ConfigFailure);
                    }
                    try
                    {
                        CurrentLogger.Info("Logging Started");
                    }
                    catch (Exception ex)
                    {
                        throw new LoggerExcetion(string.Format("{0}:failed to write initializarion log message", LOCAL_MODULE_NAME), ex,
                                                 LoggerFailureType.WriteFailure);
                    }
                }
            }
        }
 public static void Info(string msg)
 {
     CurrentLogger.Info(msg);
     Console.WriteLine(msg);
 }