示例#1
0
        public static void Write(AppSettings appSettings, string Level, string Label, string Class, string Method, string Msg, string Path = "Logs")
        {
            try
            {
                LogPaths settings = new LogPaths();
                if (appSettings.LogPaths.Exists(x => x.Label == Label))
                {
                    settings = appSettings.LogPaths.Find(x => x.Label == Label).Parameters;
                }
                else
                {
                    settings = appSettings.LogPaths.Find(x => x.Label == "Default").Parameters;
                }

                if (settings.Enabled &&
                    (Level == LogEnum.DEBUG.ToString() && appSettings.LogSettings.Debug ||
                     Level == LogEnum.INFO.ToString() && appSettings.LogSettings.Info ||
                     Level == LogEnum.ERROR.ToString() && appSettings.LogSettings.Error))
                {
                    Msg = Regex.Replace(Msg, "\n", "");
                    Msg = Regex.Replace(Msg, "\r", "");
                    Msg = Regex.Replace(Msg, "    ", " ");
                    Msg = Regex.Replace(Msg, "   ", " ");
                    Msg = Regex.Replace(Msg, "  ", " ");

                    if (Directory.Exists(Path) == false)
                    {
                        Directory.CreateDirectory(Path);
                    }
                    string pathFile = (Directory.GetCurrentDirectory() + "\\" + Path + "\\" + DateTime.Now.ToString("yyyyMMdd") + "." + Label + "." + Class + ".log").Replace("\\\\", "\\");

                    if (File.Exists(pathFile))
                    {
                        using (StreamWriter sw = File.AppendText(pathFile))
                        {
                            sw.WriteLine(DateTime.Now.ToString("yyyyMMdd") + "." + DateTime.Now.ToString("HHmmss") + $" {Level} " + Method.Trim() + " --> " + Msg);
                        }
                    }
                    else
                    {
                        using (StreamWriter sw = File.CreateText(pathFile))
                        {
                            sw.WriteLine(DateTime.Now.ToString("yyyyMMdd") + "." + DateTime.Now.ToString("HHmmss") + $" {Level} " + Method.Trim() + " --> " + Msg);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
示例#2
0
        private TestApplication RunWebApplication(IApplicationAdapter adapter, string connectionString)
        {
#if !NETCOREAPP3_1
            var physicalPath = $@"{AppDomain.CurrentDomain.ApplicationPath()}..\TestWebApplication\";
#else
            var physicalPath = $@"{AppDomain.CurrentDomain.ApplicationPath()}..\..\TestBlazorApplication\";
#endif
            LogPaths.Clear();
            LogPaths.Add(Path.Combine(Path.GetDirectoryName(physicalPath) !, "eXpressAppFramework.log"));
            LogPaths.Add(Path.Combine(@$ "{Path.GetDirectoryName(physicalPath)}\bin", Path.GetFileName(ReactiveLoggerService.RXLoggerLogPath) !));
#if !NETCOREAPP3_1
            return(((DevExpress.ExpressApp.EasyTest.WebAdapter.WebAdapter)adapter).RunWebApplication(physicalPath, 65477, connectionString));
#else
            return(((DevExpress.ExpressApp.EasyTest.BlazorAdapter.BlazorAdapter)adapter).RunBlazorApplication(physicalPath, 44318, connectionString));
#endif
        }
        private TestApplication RunWinApplication(WinAdapter adapter, string connectionString)
        {
#if !NETCOREAPP3_1_OR_GREATER
            var fileName =
                Path.GetFullPath(
                    $@"{AppDomain.CurrentDomain.ApplicationPath()}\..\TestWinApplication\TestApplication.Win.exe");
#else
            var fileName = Path.GetFullPath(ApplicationPath);
#endif
            foreach (var process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(fileName)))
            {
                process.Kill();
            }

            LogPaths.Clear();
            LogPaths.Add(Path.Combine(Path.GetDirectoryName(fileName) !, "eXpressAppFramework.log"));
            LogPaths.Add(Path.Combine(Path.GetDirectoryName(fileName) !,
                                      Path.GetFileName(ReactiveLoggerService.RXLoggerLogPath) !));
            return(adapter.RunWinApplication(fileName, connectionString));
        }
示例#4
0
        public static void Write(AppSettings appSettings, string level, string label, string Class, string method, string msg, string path = "logs")
        {
            try
            {
                LogPaths settings = new LogPaths();
                if (appSettings.LogPaths.Exists(x => x.Label == label))
                {
                    settings = appSettings.LogPaths.Find(x => x.Label == label).Parameters;
                }
                else
                {
                    settings = appSettings.LogPaths.Find(x => x.Label == "Default").Parameters;
                }

                if (settings.Enabled &&
                    (level == LogEnum.DEBUG.ToString() && appSettings.LogSettings.Debug ||
                     level == LogEnum.INFO.ToString() && appSettings.LogSettings.Info ||
                     level == LogEnum.ERROR.ToString() && appSettings.LogSettings.Error))
                {
                    msg = Regex.Replace(msg, "\n", "");
                    msg = Regex.Replace(msg, "\r", "");
                    msg = Regex.Replace(msg, "    ", " ");
                    msg = Regex.Replace(msg, "   ", " ");
                    msg = Regex.Replace(msg, "  ", " ");

                    if (Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), path)) == false)
                    {
                        Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), path));
                    }
                    string pathFile = Path.Combine(Directory.GetCurrentDirectory(), path, DateTime.Now.ToString("yyyyMMdd") + "." + label + "." + Class + ".log");

                    if (File.Exists(pathFile))
                    {
                        using (StreamWriter sw = File.AppendText(pathFile))
                        {
                            if (method.Split(new String[] { "<" }, StringSplitOptions.None).Length > 1)
                            {
                                sw.WriteLine(DateTime.Now.ToString("yyyyMMdd") + "." + DateTime.Now.ToString("HHmmss") + $" {level} " + method.Split(new String[] { "<" }, StringSplitOptions.None)[1].Split(">")[0].Trim() + " --> " + msg);
                            }
                            else
                            {
                                sw.WriteLine(DateTime.Now.ToString("yyyyMMdd") + "." + DateTime.Now.ToString("HHmmss") + $" {level} " + method + " --> " + msg);
                            }
                        }
                    }
                    else
                    {
                        using (StreamWriter sw = File.CreateText(pathFile))
                        {
                            if (method.Split(new String[] { "<" }, StringSplitOptions.None).Length > 1)
                            {
                                sw.WriteLine(DateTime.Now.ToString("yyyyMMdd") + "." + DateTime.Now.ToString("HHmmss") + $" {level} " + method.Split(new String[] { "<" }, StringSplitOptions.None)[1].Split(">")[0].Trim() + " --> " + msg);
                            }
                            else
                            {
                                sw.WriteLine(DateTime.Now.ToString("yyyyMMdd") + "." + DateTime.Now.ToString("HHmmss") + $" {level} " + method + " --> " + msg);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }