Exemplo n.º 1
0
        public void CallingMethods()
        {
            NLogLogMock logMock = new NLogLogMock();
            NLogLogger  logger  = new NLogLogger(logMock);
            bool        b       = logger.IsDebugEnabled;

            b = logger.IsErrorEnabled;
            b = logger.IsFatalEnabled;
            b = logger.IsInfoEnabled;
            b = logger.IsWarnEnabled;

            logger.Debug(null);
            logger.Debug(null, null);
            logger.DebugFormat(null, null);

            logger.Error(null);
            logger.Error(null, null);
            logger.ErrorFormat(null, null);

            logger.Warn(null);
            logger.Warn(null, null);
            logger.WarnFormat(null, null);

            logger.Info(null);
            logger.Info(null, null);
            logger.InfoFormat(null, null);

            logger.Fatal(null);
            logger.Fatal(null, null);

            logMock.debug.Should().Be(1);
            logMock.debugException.Should().Be(1);
            logMock.debugFormat.Should().Be(1);
            logMock.info.Should().Be(1);
            logMock.infoException.Should().Be(1);
            logMock.infoFormat.Should().Be(1);
            logMock.warn.Should().Be(1);
            logMock.warnException.Should().Be(1);
            logMock.warnFormat.Should().Be(1);
            logMock.error.Should().Be(1);
            logMock.errorException.Should().Be(1);
            logMock.errorFormat.Should().Be(1);
            logMock.fatal.Should().Be(1);
            logMock.fatalException.Should().Be(1);
            logMock.isDebugEnabled.Should().Be(1);
            logMock.isInfoEnabled.Should().Be(1);
            logMock.isWarnEnabled.Should().Be(1);
            logMock.isErrorEnabled.Should().Be(1);
            logMock.isFatalEnabled.Should().Be(1);
        }
Exemplo n.º 2
0
        public void Logger_Log_DelegatesToNLog()
        {
            var     target = GetLogMemoryTarget();
            ILogger log    = new NLogLogger(LogManager.GetLogger("cat"));

            log.Info("msg");
            Assert.Equal("cat|Info|msg||", target.Logs.Last());
            log.Log(LogLevel.Info, "msg");
            Assert.Equal("cat|Info|msg||", target.Logs.Last());

            log.Debug("msg");
            Assert.Equal("cat|Debug|msg||", target.Logs.Last());
            log.Log(LogLevel.Debug, "msg");
            Assert.Equal("cat|Debug|msg||", target.Logs.Last());

            log.Warn("msg");
            Assert.Equal("cat|Warn|msg||", target.Logs.Last());
            log.Log(LogLevel.Warning, "msg");
            Assert.Equal("cat|Warn|msg||", target.Logs.Last());

            log.Error("msg", new Exception("ex"));
            Assert.Equal("cat|Error|msg|ex|", target.Logs.Last());
            log.Log(LogLevel.Error, "msg", new Exception("ex"));
            Assert.Equal("cat|Error|msg|ex|", target.Logs.Last());

            log.Fatal("msg");
            Assert.Equal("cat|Fatal|msg||", target.Logs.Last());
            log.Fatal("msg", new Exception("ex"));
            Assert.Equal("cat|Fatal|msg|ex|", target.Logs.Last());
            log.Log(LogLevel.Fatal, "msg", new Exception("ex"));
            Assert.Equal("cat|Fatal|msg|ex|", target.Logs.Last());
        }
Exemplo n.º 3
0
        public void Add_File_Target()
        {
            string tmpFile = Path.GetTempFileName();
            ILog   log     = new NLogLogger("Test_Logger");

            log.AddFileTarget("Test_Target", tmpFile);
            log.Debug("DEBUG MESSAGE");
            log.Info("INFO MESSAGE");
            log.Error("ERROR MESSAGE");
            log.Warn("WARN MESSAGE");
            log.Fatal("FATAL MESSAGE");
            log.Flush();

            string logContents = File.ReadAllText(tmpFile);

            Console.Write(logContents);

            Assert.True(logContents.Contains("DEBUG MESSAGE"));
            Assert.True(logContents.Contains("INFO MESSAGE"));
            Assert.True(logContents.Contains("ERROR MESSAGE"));
            Assert.True(logContents.Contains("WARN MESSAGE"));
            Assert.True(logContents.Contains("FATAL MESSAGE"));

            File.Delete(tmpFile);
        }
Exemplo n.º 4
0
        public void WhenCallingWarnShouldRecordOneError()
        {
            // act
            _logger.Warn("Test String");

            // assert
            _memoryTarget.Logs.Count.Should().Be(1, "because we only called the method once");
            _memoryTarget.Logs.All(log => log.Contains("Warn")).Should().BeTrue("Because we only logged an Warn");
        }
Exemplo n.º 5
0
        public void TestWarn()
        {
            string msg = "warn message";

            logger.Warn(msg);
            StreamReader sr = new StreamReader(LogFullPath);

            Assert.IsTrue(sr.ReadToEnd().Contains(msg));
            sr.Close();
        }
Exemplo n.º 6
0
        private static void LogTest()
        {
            var logger = new NLogLogger(new ApplicationSettings());

            logger.Debug("Just testing debug", "Debug");
            logger.Info("Just testing info", "Info");
            logger.Warn("Just testing warning", "Warning");
            logger.Error("Just testing error", "Error");
            logger.Fatal("Testing with exception", new Exception("TestException"), "Some details again");
        }
Exemplo n.º 7
0
        public void CallMethods()
        {
            logger.Error("error message");
            logger.Info("info message");
            logger.Warn("warn message");

            StreamReader sr   = new StreamReader(LogFullPath);
            var          line = sr.ReadLine();

            while (line != null)
            {
            }
        }
Exemplo n.º 8
0
 private T ReturnRuleValue <T>(string value)
 {
     value = value.ToUpper(CultureInfo.InvariantCulture);
     try
     {
         return(ConvertValue <T>(this.rules[value]));
     }
     catch (Exception)
     {
         _nLogLogger.Warn($"Problem converting - {value}");
         return((T)Convert.ChangeType(typeof(T) == typeof(int) ? "0" : typeof(T) == typeof(bool) ? "false" : string.Empty, typeof(T)));
     }
 }
Exemplo n.º 9
0
        public LoginInternalResult Login(string username, string password, int companyNumber, string languageID, bool firstLogin, bool singleTenant)
        {
            _nLogLogger.Debug($"username {username}", "Login");
            _nLogLogger.Debug($"password {password}", "Login");
            _nLogLogger.Debug($"companyNumber {companyNumber}", "Login");
            _nLogLogger.Debug($"languageID {languageID}", "Login");
            _nLogLogger.Debug($"firstLogin {firstLogin}", "Login");
            _nLogLogger.Debug($"singleTenant {singleTenant}", "Login");
            var pdsUserLoginDataSet = new pdsUserLoginDataSet();

            pdsUserLoginDataSet.ttblUserLogin.AddttblUserLoginRow(username, password, companyNumber, languageID, firstLogin, singleTenant);
            var cErrorMessage = string.Empty;

            StopwatchUtil.Time(
                () =>
            {
                this._poLoginproxy.Login(ref this._pdsContext, ref pdsUserLoginDataSet, out cErrorMessage);
            });
            _nLogLoggerP.Trace("Login");
            if (!string.IsNullOrEmpty(cErrorMessage))
            {
                if (cErrorMessage.Contains(OperInUse))
                {
                    _nLogLogger.Warn($"Error returned - {cErrorMessage}", "PopulateLoginModel");
                }
                else
                {
                    _nLogLogger.Error($"Error returned - {cErrorMessage}", "PopulateLoginModel");
                }
            }
            if (pdsUserLoginDataSet.HasErrors)
            {
                _nLogLogger.Error("pdsUserContext is showing errors", "Login");
            }
            var result = new UserLogin();

            if (pdsUserLoginDataSet.ttblUserLogin.Count > 0)
            {
                result = UserLogin.BuildUserLoginFromRow(pdsUserLoginDataSet.ttblUserLogin[0]);
            }
            var loginInternalResult = this.PopulateLoginModel(pdsUserLoginDataSet.HasErrors, cErrorMessage, result, firstLogin);

            loginInternalResult.availUsers = new List <AvailUsers>();
            foreach (DataRow row in pdsUserLoginDataSet.ttblAvailUsers)
            {
                _nLogLogger.Debug($"Building Avail Users", "Login");
                loginInternalResult.availUsers.Add(AvailUsers.BuildAvailUsersFromRow(row));
            }
            _nLogLogger.Debug($"Finished Login", "Login");
            return(loginInternalResult);
        }
Exemplo n.º 10
0
        public static void ReportErrors(string errorMessage, int returnCode)
        {
            if (string.IsNullOrWhiteSpace(errorMessage))
            {
                return;
            }
            var nLogLogger = new NLogLogger("ReportErrors");

            if (errorMessage.Equals(SessionIdNotFound, StringComparison.InvariantCultureIgnoreCase) || errorMessage.Equals(ClientPrincipalExired, StringComparison.InvariantCultureIgnoreCase))
            {
                nLogLogger.Warn(errorMessage);
                throw new HttpResponseException(CreateReponse(HttpStatusCode.Unauthorized, CommonStrings.Token_Invalid));
            }
            nLogLogger.Info($"{returnCode}-{errorMessage}");
            throw new HttpResponseException(CreateReponse((HttpStatusCode)returnCode, errorMessage, returnCode != 401 ? CommonStrings.Error_FromSxe : CommonStrings.Token_Invalid));
        }
Exemplo n.º 11
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            var nLogLogger = new NLogLogger(SxeAuthorization);

            if (Thread.CurrentPrincipal.Identity.IsAuthenticated)
            {
                nLogLogger.Info(CommonStrings.Authorization_Passed);
                return;
            }
            nLogLogger.Warn(CommonStrings.Authorization_Failed);
            actionContext.Response         = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
            actionContext.Response.Content = new StringContent(JsonConvert.SerializeObject(new ErrorResponseJson {
                Message = CommonStrings.Token_Invalid
            }));
            if (actionContext.Response.Content.Headers.Contains("Content-Type"))
            {
                actionContext.Response.Content.Headers.Remove("Content-Type");
            }
            actionContext.Response.Content.Headers.Add("Content-Type", "application/json");
        }
Exemplo n.º 12
0
        public void CallMethods()
        {
            log.Debug("DebugMessage");
            log.Info("InfoMessage");
            log.Warn("WarnMessage");
            log.Error("ErrorMessage");
            log.Error("ErrorMessage", e);

            Assert.AreEqual("ErrorMessage", "ErrorMessage");

            StreamReader file = new StreamReader($"{DatabasePath}\\{DatabaseName}");

            while ((line = file.ReadLine()) != null)
            {
                contain = line.Contains("InfoMessage");
                if (contain == true)
                {
                    break;
                }
            }

            file.Close();
            Assert.AreEqual(contain, true);
        }
 public void Warn(string message)
 {
     _nLogLogger.Warn(message);
     _traceWriterLogger.Warn(message);
 }
Exemplo n.º 14
0
        public static Util.MP3Error ValidateMp3File(string fileName, out string strError)
        {
            ValidateOrFixFile(fileName, false);

            strError = "";
            // we might have an error in mp3val. the Log should contain the error
            if (StdOutList.Count == 0)
            {
                return(Util.MP3Error.NoError);
            }

            var error = Util.MP3Error.NoError;

            // No errors found
            if (StdOutList[0].Contains("Done!"))
            {
                return(Util.MP3Error.NoError);
            }
            else if (StdOutList[0].Contains(@"No supported tags in the file"))
            {
                return(Util.MP3Error.NoError); // Fixed by MPTagThat :-)
            }
            else if (StdOutList[0].Contains(@"Garbage at the beginning of the file"))
            {
                error    = Util.MP3Error.Fixable; // Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"Garbage at the end of the file"))
            {
                error    = Util.MP3Error.Fixable; // Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"MPEG stream error, resynchronized successfully"))
            {
                error    = Util.MP3Error.Fixable; // Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"This is a RIFF file, not MPEG stream"))
            {
                error    = Util.MP3Error.Fixable; // Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"It seems that file is truncated or there is garbage at the end of the file"))
            {
                error    = Util.MP3Error.Fixable; // Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"Wrong number of MPEG frames specified in Xing header"))
            {
                error    = Util.MP3Error.Fixable; // Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"Wrong number of MPEG data bytes specified in Xing header"))
            {
                error    = Util.MP3Error.Fixable; // Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"Wrong number of MPEG frames specified in VBRI header"))
            {
                error    = Util.MP3Error.Fixable; // Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"Wrong number of MPEG data bytes specified in VBRI header"))
            {
                error    = Util.MP3Error.Fixable; // Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"Wrong CRC in"))
            {
                error    = Util.MP3Error.Fixable; // Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"Several APEv2 tags in one file"))
            {
                return(Util.MP3Error.NoError); // Handled by MPTagThat
            }
            else if (StdOutList[0].Contains(@"Too few MPEG frames"))
            {
                error    = Util.MP3Error.NonFixable; // Non Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"VBR detected, but no VBR header is present. Seeking may not work properly"))
            {
                error    = Util.MP3Error.NonFixable; // Non Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"Different MPEG versions or layers in one file"))
            {
                error    = Util.MP3Error.NonFixable; // Non Fixable error
                strError = StdOutList[0];
            }
            else if (StdOutList[0].Contains(@"Non-layer-III frame encountered"))
            {
                error    = Util.MP3Error.NonFixable; // Non Fixable error
                strError = StdOutList[0];
            }

            if (error == Util.MP3Error.Fixable)
            {
                log.Warn($"MP3 Validate Fixable error: {StdOutList[0]}");
            }
            else if (error == Util.MP3Error.NonFixable)
            {
                log.Warn($"MP3 Validate Non-Fixable error: {StdOutList[0]}");
            }

            // This happens, if we fixed an error
            if (StdOutList.Count > 2)
            {
                if (StdOutList[StdOutList.Count - 2].Contains(@"FIXED:"))
                {
                    error = Util.MP3Error.Fixed;
                }
            }

            return(error);
        }