设置自定义日志路径

时间:2017-11-16 16:47:08

标签: vb.net

根据MSDN的信息,我应该能够设置FileLogTraceListener的CustomLocation属性。这样做,我发现当我离开使用默认属性时,日志记录停止。我不确定我在这里做错了什么。我错过了什么?

Module PackingListPrintModule

  'Establish application path, replace appPath on deployment
  Public appPath As String = System.IO.Path.GetDirectoryName(
        System.Reflection.Assembly.GetExecutingAssembly().Location)
  Public Property CustomLocation As String
    Public logtrace As New FileLogTraceListener

  Function setCustomLogLocation() As String
      logtrace.CustomLocation = appPath
      setCustomLogLocation = appPath
  End Function

      Sub Main()

        Try
            'Test use the logtrace instace to write a line
            logtrace.Append = True
            logtrace.WriteLine("Set the log and application path to" & setCustomLogLocation())

           'Test use of the Log.WriteEntry method to write a line (Works with default settings)
                My.Application.Log.WriteEntry("Checking that save location exists")
                logtrace = Nothing

        Catch ex as Exception
              msgbox(ex.Message)
        Finally
              logtrace = Nothing
              Environment.Exit(0)
        End Sub
    End Module

0 个答案:

没有答案