欢迎光临
我们一直在努力

用以在记录文件中写入自定义的调试信息(主要是时间)的组件-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

====================================================================
tracespy – 用以在记录文件中写入自定义的调试信息(开发者:林健)
====================================================================

属性:
       tracefilename        – 记录文件名

方法:
   ★文本写入方面
       writetext            – 写入自定义文本
       clearalltext         – 清除所有文本
   ★时间记录方面
       settimepoint         – 设置时间起点
       gettimespanfrominit  – 询问时间跨度(距离时间起点)
       gettimespanfromprev  – 询问时间跨度(距离上次询问时间)

====================================================================

public class tracespy

    记录文件名
    public shared tracefilename as string = "trace.txt"

    时间起点(初始为当前时刻)
    private shared inittimepoint as long = now.ticks

    上次询问时间点(初始为当前时刻)
    private shared prevtimepoint as long = now.ticks

    写入自定义文本
    public shared sub writetext(byval str as string, optional byval showtime as boolean = false)
        tracespyfilewriter.writetext(str, showtime)
    end sub

    清除所有文本
    public shared sub clearalltext()
        tracespyfilewriter.clearalltext()
    end sub

    设置时间起点
    public shared sub settimepoint(optional byval note as string = "")
        inittimepoint = now.ticks
        prevtimepoint = now.ticks
        tracespyfilewriter.writetext("设置时间起点[" & note & "]。")
    end sub

    询问时间跨度(距离时间起点)
    public shared function gettimespanfrominit(optional byval note as string = "") as decimal
        prevtimepoint = now.ticks
        dim span as decimal
        span = cdec(prevtimepoint – inittimepoint) / 10000d
        tracespyfilewriter.writetext("询问时间跨度[" & note & "],距离时间起点为" & span.tostring() & "毫秒。")
        return span
    end function

    询问时间跨度(距离上次询问时间)
    public shared function gettimespanfromprev(optional byval note as string = "") as decimal
        dim recttimepoint as long = now.ticks
        dim span as decimal
        span = cdec(recttimepoint – prevtimepoint) / 10000d
        prevtimepoint = recttimepoint
        tracespyfilewriter.writetext("询问时间跨度[" & note & "],距离上次询问时间为" & span.tostring() & "毫秒。")
        return span
    end function

end class

friend class tracespyfilewriter

    private shared filewriter as system.io.streamwriter

    向文件中写入一个字串
    friend shared sub writetext(byval str as string, optional byval showtime as boolean = false)
        if tracespy.tracefilename = string.empty then
            exit sub
        end if
        filewriter = new system.io.streamwriter(tracespy.tracefilename, true, text.encoding.default)
        dim words as string
        words = str
        if showtime then
            words &= " @ " & now.tolongdatestring & " " & now.tolongtimestring
        end if
        filewriter.writeline(words)
        filewriter.close()
    end sub

    清除记录文件
    friend shared sub clearalltext()
        if tracespy.tracefilename = string.empty then
            exit sub
        end if
        filewriter = new system.io.streamwriter(tracespy.tracefilename, false, text.encoding.default)
        filewriter.write("")
        filewriter.close()
    end sub

end class

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用以在记录文件中写入自定义的调试信息(主要是时间)的组件-.NET教程,Asp.Net开发
分享到: 更多 (0)