62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using Newtonsoft.Json;
|
|
|
|
namespace CoreProfilerExample.Common.Options
|
|
{
|
|
public class CoreProfilerOption
|
|
{
|
|
/// <summary>
|
|
/// 資料保存上限(Session)。
|
|
/// </summary>
|
|
[JsonProperty("circularBufferSize")]
|
|
public int CircularBufferSize { get; set; } = 200;
|
|
/// <summary>
|
|
/// 要過濾掉的項目。
|
|
/// </summary>
|
|
[JsonProperty("filters")]
|
|
public IEnumerable<CoreProfilerOptionFilter> 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<CoreProfilerOption>(json);
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
return new CoreProfilerOption().Save(filename);
|
|
}
|
|
}
|
|
}
|