在Windows 10 UWP应用中更改MetroLog文件夹和文件名 [英] Change MetroLog folder and file name in Windows 10 UWP app

查看:140
本文介绍了在Windows 10 UWP应用中更改MetroLog文件夹和文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道是否有人有在Windows 10 UWP应用程序上使用MetroLog的经验.我不太熟悉它,只是开始使用它.为了不复制代码并创建冗长的帖子,请

Wondering if anybody has experience using MetroLog on a Windows 10 UWP app. I am not too familiar with it and just started using it. For the purpose of not duplicating code and creating a long post, I followed this walk through step by step.

我有一个简单的问题.使用此指南和MetroLog的默认实现,日志文件存储在我的应用程序本地文件夹中的一个名为"MetroLog"的文件夹中.此外,文件名只是命名为"log-20170206.log"

The question I have is a simple one though. With this guide and the default implementation of MetroLog, the log files are stored in a folder named "MetroLog" within my app local folder. Furthermore, the file name is just named "log - 20170206.log"

我想自定义路径和文件名.首先,我希望该路径仅是我的应用程序根本地文件夹路径,而不是另一个名为MetroLog的子文件夹.我还希望日志文件成为我的应用程序的名称,而不仅仅是"log".

I want to customize the path and the filename. First, I want the path to just be my application root local folder path and not in another subfolder named MetroLog. I also want the log file to be the name of my application instead of just "log".

例如,我希望我的文件夹和文件名如下所示:

For example, I want my folder and file name to be like the following:

private const string logFileName = @"MyAppName.log";
var filePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, logFileName);

我知道记录器使用StreamingFileTarget,但是我看不到可以指定路径和文件名.

I know the logger uses a StreamingFileTarget but I did not see that I could specify the path and file name.

有想法吗?

推荐答案

首先,我希望该路径仅是我的应用程序根本地文件夹路径,而不是另一个名为MetroLog的子文件夹中.

First, I want the path to just be my application root local folder path and not in another subfolder named MetroLog.

如果您已在github上检查MetroLog的源代码,则会发现在"MetroLog.Shared.WinRT"项目中创建"MetroLog"子文件夹. 第34行该子文件夹路径为固定在其源代码中.

If you've checked the source code of MetroLog on github, you'll find that creating "MetroLog" subfolder is in "MetroLog.Shared.WinRT" project. Line 34 This subfolder path is fixed in its source code.

我还希望日志文件成为我的应用程序的名称,而不仅仅是"log".

I also want the log file to be the name of my application instead of just "log".

同一件事,您将看到创建日志文件的命名方法在"MetroLog.Shared"项目中. 第33行

The same thing, you'll see the naming method of creating log file is in the "MetroLog.Shared" project. Line 33

因此,如果要获得目标,则需要更改该源代码中的两个位置.并重建一个自定义版本.之后,您可以添加对自定义版本"MetroLog"库的引用.

So, if you want to get your target, you'll need to change the two places in that source code. And rebuild a custom version. After that, you could add reference to your custom version "MetroLog" library.

这篇关于在Windows 10 UWP应用中更改MetroLog文件夹和文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆