Ejemplo n.º 1
0
        public void RefreshImplicits()
        {
            string logJson = FileExt.ReadAllText(RootConfig.LogJsonFileLocation);

            logJson = "[" + logJson.Replace('\n', ',') + "]";

            var loadedLog = JsonConvert.DeserializeObject(logJson) as JArray;

            ParsedJsonLog = new JArray();

            foreach (var log in loadedLog)
            {
                string callerMethod = log["Properties"]?["CallerMethodName"]?.ToString();
                if (callerMethod != null && !callerMethod.Contains("uhttpsharp"))
                {
                    ParsedJsonLog.Add(log);
                }
            }

            List <string> logLines = new List <string>();

            foreach (var entry in ParsedJsonLog.Reverse())
            {
                string logText = entry["RenderedMessage"].ToString();
                logLines.Add(logText);
            }

            TextLog = string.Join("\n", logLines);

            TextLogHtml = string.Join("\n", from log in logLines
                                      select $"<p>{log.Replace("\n", "<br>")}</p>");

            string tabHtml = "<span style='display:inline-block;width:2em;'></span>";

            TextLogHtml = TextLogHtml.Replace("\t", tabHtml);
            TextLogHtml = TextLogHtml.Replace("  ", tabHtml);

            RefreshedAt = DateTime.Now;
        }
Ejemplo n.º 2
0
        public App()
        {
            FileExt.TryDelete(RootConfig.LogTextFileLocation);
            FileExt.TryDelete(RootConfig.LogJsonFileLocation);

            Serilog.Debugging.SelfLog.Enable((msg) =>
            {
                Debug.WriteLine("Serilog says: " + msg);
            });



            string logOutputTemplate = "{Timestamp:HH:mm:ss} [{Level} {CallerMethodName}] {Message}{NewLine}{Exception}";

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Verbose()
                         .Enrich.FromLogContext()
                         //.Enrich.With(new SerilogBreakOnLogEnricher(LogEventLevel.Error))
                         .Enrich.With(new SerilogCallingMethodEnricher())
                         .WriteTo.File(RootConfig.LogTextFileLocation, outputTemplate: logOutputTemplate)
                         .WriteTo.File(new JsonFormatter(null, true), RootConfig.LogJsonFileLocation)
                         .WriteTo.Observers(events => events.Subscribe(new LogObserver().OnMessage((a, b) => Logged?.Invoke(a, b))))
                         .CreateLogger();

            Logger = Log.ForContext <App>();

            DispatcherUnhandledException += App_DispatcherUnhandledException;

            AppDomain.CurrentDomain.UnhandledException   += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;

            var cmd = Environment.CommandLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (cmd.Any(c => c.ToLower() == "-debug"))
            {
                Debugger.Launch();
            }
        }