using Newtonsoft.Json; namespace CoreProfilerExample.Common.Options { public class CoreProfilerOption { /// /// 資料保存上限(Session)。 /// [JsonProperty("circularBufferSize")] public int CircularBufferSize { get; set; } = 200; /// /// 要過濾掉的項目。 /// [JsonProperty("filters")] public IEnumerable Filters { get; set; } = [ new CoreProfilerOptionFilter { Key = "/coreprofiler", Value = "/coreprofiler", Type = "CoreProfiler.ProfilingFilters.NameContainsProfilingFilter, CoreProfiler", }, new CoreProfilerOptionFilter { Key = "static files", Value = "ico,jpg,js,css,svg,json,ttf,woff,woff2,eot", Type = "CoreProfiler.ProfilingFilters.FileExtensionProfilingFilter, CoreProfiler", }, ]; public CoreProfilerOption Save(string filename) { var json = JsonConvert.SerializeObject(this, Formatting.Indented); File.WriteAllText(filename, json); return this; } public static CoreProfilerOption UseCoreProfilerSetting() { var filename = Path.Combine(AppContext.BaseDirectory, "coreprofiler.json"); if (File.Exists(filename)) { try { var json = File.ReadAllText(filename); return JsonConvert.DeserializeObject(json); } catch { } } return new CoreProfilerOption().Save(filename); } } }