【问题标题】:Using MetroLog in C# to direct the logs into a specified File Location在 C# 中使用 MetroLog 将日志定向到指定的文件位置
【发布时间】:2017-09-26 08:53:00
【问题描述】:

类似于 java.util.logging 包,我正在尝试在 C# 日志记录实现中使用 MetroLog。在 MetroLog 的 documentation 中,我找不到相同的示例。

我的sn-p

var naming = new FileNamingParameters()
                    {
                        IncludeLevel = false,
                        IncludeLogger = false,
                        IncludeSequence = false,
                        IncludeSession = false,
                        IncludeTimestamp = FileTimestampMode.None
                    };

var info = GetLogEventInfo();
var filename = naming.GetFilename(new LogWriteContext(), info);

有什么方法可以通过编程设置我的文件名?

文档显示了使用默认日志记录位置的方法。

【问题讨论】:

    标签: c# windows logging uwp metrolog


    【解决方案1】:

    您不能使用 Metro 日志动态设置文件名,您唯一可以做的是将 FileNamingParameters.FileTimestampMode 设置为 Date(用于为每天创建一个文件)或 DateTime 用于包含日期和时间的文件名两者都有。

    如果您想要自己的文件名,请使用库的open sourced version,然后按以下方法更改文件命名逻辑-FileTargetBase.cs中的GetOrCreateStreamWriterForFile

    【讨论】:

      猜你喜欢
      • 2018-10-04
      • 1970-01-01
      • 2021-08-19
      • 2013-04-15
      • 1970-01-01
      • 1970-01-01
      • 2011-01-31
      • 2011-03-21
      • 2018-03-24
      相关资源
      最近更新 更多