Exemplo n.º 1
0
        private FeatherLogger GetFeatherLoggerForTestingLogLevels(FeatherLoggerTraceLevel traceLevel)
        {
            var logger = new FeatherLogger(
                logMode: FeatherLoggerLogMode.LogAsYouGo,
                traceLevel: traceLevel,
                folderName: null,
                filename: "log",
                hasTimestampInFilename: false,
                extension: _loggerFileExtension);

            return(logger);
        }
Exemplo n.º 2
0
        }                                                // Contains text when the logger was created in some wrong state

        public FeatherLogger(FeatherLoggerLogMode logMode, FeatherLoggerTraceLevel traceLevel, string folderName,
                             string filename, bool hasTimestampInFilename, string extension)
        {
            ErrorMessage = String.Empty;
            TraceLevel   = FeatherLoggerTraceLevel.Nothing;

            try
            {
                LogMode    = logMode;
                TraceLevel = traceLevel;

                var blah  = System.AppDomain.CurrentDomain.FriendlyName;
                var blah2 = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                var blah3 = System.Reflection.Assembly.GetCallingAssembly();
                var blah4 = System.Reflection.Assembly.GetExecutingAssembly();

                FolderName = !String.IsNullOrEmpty(folderName) ? folderName :
                             Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);



                FileName = filename + (hasTimestampInFilename ? DateTime.Now.ToString("yyyyMMddhhmmss") : "") +
                           (String.IsNullOrEmpty(extension) ? "" : "." + extension);

                ResetTabLevel();

                if (LogMode == FeatherLoggerLogMode.LogAsYouGo)
                {
                    CreateFolderForLogFileIfDoesntExist();
                }
                else if (LogMode == FeatherLoggerLogMode.LogDump)
                {
                    _allText = new StringBuilder();
                }
                else
                {
                    throw new NotImplementedException("FeatherLogger.ctor does not support LogMode " + LogMode);
                }

                WriteFirstLine();
            }
            catch (Exception ex)
            {
                this.ErrorMessage = "EXCEPTION: " + ex.Message +
                                    ((ex.InnerException == null) ? "" : " / INNER EXCEPTION: " + ex.InnerException.Message);
                throw ex;
            }
        }
Exemplo n.º 3
0
        // TODO UNTESTED
        private static void InitializeValuesFromIni(Dictionary <string, string> keyValuePairs)
        {
            foreach (var oneKeyValuePair in keyValuePairs)
            {
                var key   = oneKeyValuePair.Key;
                var value = oneKeyValuePair.Value;

                if (key == "GoodAnswerPoints")
                {
                    GlobalObjects.GoodAnswerPoints = Convert.ToInt32(value);
                }
                else if (key == "GoodAnswerPrct")
                {
                    GlobalObjects.GoodAnswerPrct = double.Parse(value, CultureInfo.InvariantCulture);
                }
                else if (key == "BadAnswerPoints")
                {
                    GlobalObjects.BadAnswerPoints = Convert.ToInt32(value);
                }
                else if (key == "BadAnswerPrct")
                {
                    GlobalObjects.BadAnswerPrct = double.Parse(value, CultureInfo.InvariantCulture);
                }
                else if (key == "GoodAnswerPoints")
                {
                    GlobalObjects.GoodAnswerPoints = Convert.ToInt32(value);
                }
                else if (key == "BadAnswerPoints")
                {
                    GlobalObjects.BadAnswerPoints = Convert.ToInt32(value);
                }
                else if (key == "GoodAnswerPrct")
                {
                    GlobalObjects.GoodAnswerPrct = double.Parse(value, CultureInfo.InvariantCulture);
                }
                else if (key == "BadAnswerPrct")
                {
                    GlobalObjects.BadAnswerPrct = double.Parse(value, CultureInfo.InvariantCulture);
                }
                else if (key == "TraceLevel")
                {
                    FeatherLoggerTraceLevel ParsedValue = (FeatherLoggerTraceLevel)
                                                          Enum.Parse(typeof(FeatherLoggerTraceLevel), value, true);
                    GlobalObjects.FeatherLoggerTraceLevel = ParsedValue;
                }
                else if (key == "LogMode")
                {
                    FeatherLoggerLogMode ParsedValue = (FeatherLoggerLogMode)
                                                       Enum.Parse(typeof(FeatherLoggerLogMode), value, true);
                    GlobalObjects.FeatherLoggerMode = ParsedValue;
                }
                else if (key == "FolderName")
                {
                    GlobalObjects.FolderName = value;
                }
                else if (key == "Language")
                {
                    WindowsLanguage ParsedValue = (WindowsLanguage)
                                                  Enum.Parse(typeof(WindowsLanguage), value, true);
                    GlobalObjects.Language = ParsedValue;
                }
                else if (key == "FreePointsOnNextLevel")
                {
                    GlobalObjects.FreePointsOnNextLevel = Convert.ToInt32(value);
                }
                else if (key == "LevelDownOnPoints")
                {
                    GlobalObjects.LevelDownOnPoints = Convert.ToInt32(value);
                }
                else if (key == "PointsAfterLevelDown")
                {
                    GlobalObjects.PointsAfterLevelDown = Convert.ToInt32(value);
                }
                else if (key == "RandomPointsGainAfterLevelChange")
                {
                    GlobalObjects.RandomPointsGainAfterLevelChange = Convert.ToInt32(value);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Invalid key '" + key + "' found in ini file");
                }
            }
        }