(MVC) MVC (2018)

<<назад Logger.vb (Contoso University).

   1:  Imports Microsoft.VisualBasic
   2:  Imports System.Diagnostics
   3:   
   4:  Namespace Log1
   5:   
   6:      Public Class Logger1
   7:          Implements ILogger
   8:   
   9:          Public Sub Information(message As String) Implements ILogger.Information
  10:              Debug.WriteLine(message)
  11:              Trace.TraceInformation(message)
  12:          End Sub
  13:   
  14:          Public Sub Information(fmt As String, ParamArray vars() As Object) Implements ILogger.Information
  15:              Debug.WriteLine(fmt, vars)
  16:              Trace.TraceInformation(fmt, vars)
  17:          End Sub
  18:   
  19:          Public Sub Information(exception As Exception, fmt As String, ParamArray vars() As Object) Implements ILogger.Information
  20:              Debug.WriteLine(FormatExceptionMessage(exception, fmt, vars))
  21:              Trace.TraceInformation(FormatExceptionMessage(exception, fmt, vars))
  22:          End Sub
  23:   
  24:          Public Sub Warning(message As String) Implements ILogger.Warning
  25:              Debug.WriteLine(message)
  26:              Trace.TraceWarning(message)
  27:          End Sub
  28:   
  29:          Public Sub Warning(fmt As String, ParamArray vars() As Object) Implements ILogger.Warning
  30:              Debug.WriteLine(fmt, vars)
  31:              Trace.TraceWarning(fmt, vars)
  32:          End Sub
  33:   
  34:          Public Sub Warning(exception As Exception, fmt As String, ParamArray vars() As Object) Implements ILogger.Warning
  35:              Debug.WriteLine(FormatExceptionMessage(exception, fmt, vars))
  36:              Trace.TraceWarning(FormatExceptionMessage(exception, fmt, vars))
  37:          End Sub
  38:   
  39:          Public Sub [Error](message As String) Implements ILogger.Error
  40:              Debug.WriteLine(message)
  41:              Trace.TraceError(message)
  42:          End Sub
  43:   
  44:          Public Sub [Error](fmt As String, ParamArray vars() As Object) Implements ILogger.Error
  45:              Debug.WriteLine(fmt, vars)
  46:              Trace.TraceError(fmt, vars)
  47:          End Sub
  48:   
  49:          Public Sub [Error](exception As Exception, fmt As String, ParamArray vars() As Object) Implements ILogger.Error
  50:              Debug.WriteLine(FormatExceptionMessage(exception, fmt, vars))
  51:              Trace.TraceError(FormatExceptionMessage(exception, fmt, vars))
  52:          End Sub
  53:   
  54:          Public Sub TraceApi(componentName As String, method As String, timespan As TimeSpan) Implements ILogger.TraceApi
  55:              TraceApi(componentName, method, timespan, "")
  56:          End Sub
  57:   
  58:          Public Sub TraceApi(componentName As String, method As String, timespan As TimeSpan, fmt As String, ParamArray vars() As Object) Implements ILogger.TraceApi
  59:              TraceApi(componentName, method, timespan, String.Format(fmt, vars))
  60:          End Sub
  61:   
  62:          Public Sub TraceApi(componentName As String, method As String, timespan As TimeSpan, properties As String) Implements ILogger.TraceApi
  63:              Dim message As String = String.Concat("Component:", componentName, ";Method:", method, ";Timespan:", timespan.ToString(), ";Properties:", properties)
  64:              Debug.WriteLine(message)
  65:              Trace.TraceInformation(message)
  66:          End Sub
  67:   
  68:          Private Shared Function FormatExceptionMessage(ByVal exception As Exception, ByVal fmt As String, ByVal vars As Object()) As String
  69:              Dim sb = New StringBuilder()
  70:              sb.Append(String.Format(fmt, vars))
  71:              sb.Append(" Exception: ")
  72:              sb.Append(exception.ToString())
  73:              Return sb.ToString()
  74:          End Function
  75:      End Class
  76:  End Namespace


Comments ( )
Link to this page: //www.vb-net.com/EF-missing-FAQ/Code/Logger.vb.htm
< THANKS ME>