Esempio n. 1
0
        /// <summary>
        /// ログを保存する。(文字列)
        /// 引数として必要なのは、保存する文字列のみ
        /// </summary>
        /// <param name="s">保存する文字列</param>
        /// <param name="file">未設定でよい</param>
        /// <param name="line">未設定でよい</param>
        /// <param name="member">未設定でよい</param>
        public static void SaveLog(
            string s,
            LogDummy dummy = null,
            [CallerFilePath] string file     = "",
            [CallerLineNumber] int line      = 0,
            [CallerMemberName] string member = ""
            )
        {
            if (!fLog)
            {
                return;
            }
            CheckReOpen();
            bool mutFlg = false;

            try {
                mutFlg = mut.WaitOne();
                if (mutFlg)
                {
                    fs.Seek(0, SeekOrigin.End);
                    sw.Write($"{DateTime.Now:MM/dd HH:mm:ss.fff}{TB}{Path.GetFileName(file)}({line})");
                    sw.Write($"{TB}{s.Replace($"{BR}", $"{BR}{TB}{TB}")}{BR}");
                    sw.Flush();
                }
            } catch (Exception) {
            } finally {
                if (mutFlg)
                {
                    mut.ReleaseMutex();
                }
            }
        }
Esempio n. 2
0
        public static void SaveLog(
            Exception ex,
            string sql,
            SQLiteParameter[] sqlParams,
            LogDummy dummy = null,
            [CallerFilePath] string file     = "",
            [CallerLineNumber] int line      = 0,
            [CallerMemberName] string member = ""
            )
        {
            if (!fLog)
            {
                return;
            }
            CheckReOpen();
            bool mutFlg = false;

            try {
                mutFlg = mut.WaitOne();
                if (mutFlg)
                {
                    fs.Seek(0, SeekOrigin.End);
                    sw.Write($"{DateTime.Now:MM/dd HH:mm:ss.fff)}{TB}{Path.GetFileName(file)}({line}){TB}{member}{BR}");
                    var exmes = Regex.Replace(ex.ToString(), @"^   場所 System.*\n?", "", RegexOptions.Multiline).Replace($"{BR}", $"{BR}{TB}{TB}");
                    sw.Write($"{TB}EXP:{TB}{exmes}{BR}");
                    if (ex is SQLiteException sqlexp)
                    {
                        sw.Write($"{TB}SQLERR:{TB}{sqlexp.ErrorCode}:{sqlexp.Message.Replace($"{BR}", $"{BR}{TB}{TB}")}{BR}");
                        if (sqlexp.InnerException is SQLiteException iex)
                        {
                            sw.Write($"{TB}SQLERR:{TB}{iex.ErrorCode}:{iex.Message.Replace($"{BR}", $"{BR}{TB}{TB}")}{BR}");
                        }
                    }
                    sw.Write($"{TB}SQL:{TB}{sql.Replace($"{BR}", $"{BR}{TB}{TB}")}{BR}");
                    if (sqlParams != null)
                    {
                        foreach (SQLiteParameter p in sqlParams)
                        {
                            sw.Write($"{TB}{TB}{p.ParameterName}:{p.Value.__ToStrF().Replace($"{BR}", $"{BR}{TB}{TB}")}{BR}");
                        }
                    }
                    sw.Write($"{BR}");
                    sw.Flush();
                }
            } catch (Exception) {
            } finally {
                if (mutFlg)
                {
                    mut.ReleaseMutex();
                }
            }
        }
        public void LoggingSetupWorksCorrectly()
        {
            // arrange
            var containerDummy = new Mock <ContainerSetup>();
            var logDummy       = new LogDummy();

            containerDummy.Setup(t => t.ResolveMany <BaseLogConfiguration>())
            .Returns(new List <BaseLogConfiguration> {
                logDummy
            });

            // act
            containerDummy.Object.SetupLogging();

            // assert
            logDummy.IsActive.Should().BeTrue();
            logDummy.WasApplied.Should().BeTrue();
        }