小编BWh*_*lan的帖子

为什么 RollingInterval.Day 不断创建新的 Serilog 日志文件?

我使用 Serilog 作为我的程序的记录器。尝试制作滚动间隔文件,将 yyyymmdd 日期附加到每个文件。

下面的代码正是我一直使用的代码,它在 4-5 天的时间里有效地测试和进一步开发了我的 UWP 应用程序。然后我认为我的应用程序开始创建多个具有相同日期的文件,标题为“logs-yyyymmdd_01”、“logs-yyyymmdd_02”等。

这是在 MainPageViewModel 构造函数中

            Log.Logger = new LoggerConfiguration().MinimumLevel.Debug()
            .WriteTo.File(this.GetFile("logs-"), rollingInterval: RollingInterval.Day)
            .CreateLogger();

Run Code Online (Sandbox Code Playgroud)
        public string GetFile(String FileName)
        {
            string s = ApplicationData.Current.LocalFolder.Path;
            return s + "\\" + FileName;
        }
Run Code Online (Sandbox Code Playgroud)

我怀疑它多次调用构造函数,这可能是问题的一部分。但是滚动间隔应该只在新的一天时创建一个新文件,对吧?因为当应用程序多次启动时,它过去会使用与今天日期相对应的任何文件。因此,我要么需要一种方法使 Log.Logger 静态以使其具有通用性,要么需要一种方法使其仅使用一个文件。任何帮助将非常感激

c# xaml serilog uwp

5
推荐指数
1
解决办法
1万
查看次数

Serilog日志文件写入时如何触发事件?

我正在尝试在我的 UWP 应用程序中显示 Serilog“logs.txt”文件的内容。我已成功显示它,但现在我希望它在创建新日志事件时自动刷新。

到目前为止,我尝试创建一个 ContentsChanged 事件侦听器来订阅本地文件驱动器中 .txt 文件中的更改。

private async void CreateFileUpdater()
{
    List<string> fileTypeFilter = new List<string>();
    fileTypeFilter.Add(".txt");
    var options = new Windows.Storage.Search.QueryOptions(Windows.Storage.Search.CommonFileQuery.OrderByName, fileTypeFilter);
    var query = ApplicationData.Current.LocalFolder.CreateFileQueryWithOptions(options);
            //subscribe on query's ContentsChanged event
    query.ContentsChanged += Query_ContentsChanged;
    var files = await query.GetFilesAsync();
}

private void Query_ContentsChanged(Windows.Storage.Search.IStorageQueryResultBase sender, object args)
{
    ReadFileAsync(); //This updates the bound variable to display in UI
}
Run Code Online (Sandbox Code Playgroud)

但是,当新的日志事件添加到日志文件时,它似乎无法正确触发。所以我想知道 Serilog 本身是否有一个我在文档中没有看到的事件,或者是否有更好的方法来检测文件中的更改或何时将内容添加到文件中。我只想调用某种事件,以便我可以触发 ReadFilesAsync() 函数来更新绑定到我的 UI 的变量。

谢谢你的帮助!

c# xaml serilog uwp

2
推荐指数
1
解决办法
3655
查看次数

如何在 UWP 中使用代码模拟 Tab 键按下

我正在尝试使用屏幕上的按钮来执行 Tab 和反向 Tab 的功能。我希望应用程序能够通过“分段”按钮和其他这些按钮进行切换,然后用户能够使用 Enter 键选择一个。试图使程序完全可以通过键盘导航。

演示布局

我尝试过使用 KeyDown 事件,然后使用定向焦点导航,但我更希望让系统模拟按 Tab 键以跟随选项卡路径。

这是我一直在尝试解决的代码,但它并不完全是我想要的功能。

        private void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            DependencyObject candidate = null;

            var options = new FindNextElementOptions()
            {
                SearchRoot = WeldPGrid,
                XYFocusNavigationStrategyOverride = XYFocusNavigationStrategyOverride.Projection
            };

            switch (e.Key)
            {
                case Windows.System.VirtualKey.Up:
                    candidate =
                        FocusManager.FindNextElement(
                            FocusNavigationDirection.Up, options);
                    break;
                case Windows.System.VirtualKey.Down:
                    candidate =
                        FocusManager.FindNextElement(
                            FocusNavigationDirection.Down, options);
                    break;
                case Windows.System.VirtualKey.Left:
                    candidate = FocusManager.FindNextElement(
                        FocusNavigationDirection.Left, options);
                    break;
                case Windows.System.VirtualKey.Right:
                    candidate =
                        FocusManager.FindNextElement(
                            FocusNavigationDirection.Right, options);
                    break;
            }
            // Also consider whether candidate is a …
Run Code Online (Sandbox Code Playgroud)

c# xaml mvvm uwp

0
推荐指数
1
解决办法
2803
查看次数

标签 统计

c# ×3

uwp ×3

xaml ×3

serilog ×2

mvvm ×1