zoukankan      html  css  js  c++  java
  • Wp7 日志 工具

    主要有三个功能

      1、输出到OutPut中

      2、用MessageBox显示出来

      3、保存到独立存储中

    不多说了,看代码

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

      1 using System;
    2 using System.Net;
    3 using System.Windows;
    4 using System.Windows.Controls;
    5 using System.Windows.Documents;
    6 using System.Windows.Ink;
    7 using System.Windows.Input;
    8 using System.Windows.Media;
    9 using System.Windows.Media.Animation;
    10 using System.Windows.Shapes;
    11 using System.Diagnostics;
    12 using System.IO.IsolatedStorage;
    13 using System.IO;
    14
    15 namespace TrainQuery.Common
    16 {
    17 ///<summary>
    18 ///
    19 /// 日志处理工具
    20 ///
    21 /// @author luxiaofeng
    22 /// @date 2011/10/30
    23 ///</summary>
    24 public class LogUtils
    25 {
    26 ///<summary>
    27 /// 是否输出到OutPut
    28 ///</summary>
    29 public static bool isPrintOutPut = true;
    30 ///<summary>
    31 /// 是否使用MessageBox显示
    32 ///</summary>
    33 public static bool isShowMessageBox = true;
    34 ///<summary>
    35 /// 是否写入文件
    36 ///</summary>
    37 public static bool isWriteFile = true;
    38 ///<summary>
    39 /// 默认日志文件名
    40 ///</summary>
    41 public static string defaultFileName = "logs.txt";
    42 ///<summary>
    43 /// 默认tag名
    44 ///</summary>
    45 public static string tag = "LogUtils";
    46
    47 ///<summary>
    48 /// 输出信息到output
    49 ///</summary>
    50 ///<param name="tag">标签</param>
    51 ///<param name="message">要打印的信息</param>
    52 public static void printWithOutPut(string message)
    53 {
    54 printWithOutPut(isPrintOutPut, tag, message);
    55 }
    56
    57 ///<summary>
    58 /// 输出信息到output
    59 ///</summary>
    60 ///<param name="tag">标签</param>
    61 ///<param name="message">要打印的信息</param>
    62 public static void printWithOutPut(string tag, string message)
    63 {
    64 printWithOutPut(isPrintOutPut, tag, message);
    65 }
    66
    67 ///<summary>
    68 /// 输出信息到output
    69 ///</summary>
    70 ///<param name="flag">是否输出</param>
    71 ///<param name="tag"></param>
    72 ///<param name="message"></param>
    73 public static void printWithOutPut(bool flag, string tag, string message)
    74 {
    75 if (isPrintOutPut)
    76 {
    77 Debug.WriteLine(" {0} -------- {1} : {2}", DateTime.Now.ToLongTimeString(), tag, message);
    78 }
    79 }
    80
    81 ///<summary>
    82 /// 用MessageBox显示信息
    83 ///</summary>
    84 ///<param name="message"></param>
    85 public static void showMessageBox(string message)
    86 {
    87 showMessageBox(isShowMessageBox, message);
    88 }
    89
    90 ///<summary>
    91 /// 用MessageBox显示信息
    92 ///</summary>
    93 ///<param name="flag">是否显示</param>
    94 ///<param name="message"></param>
    95 public static void showMessageBox(bool flag, string message)
    96 {
    97 if (isShowMessageBox)
    98 {
    99 MessageBox.Show(message);
    100 }
    101 }
    102
    103 ///<summary>
    104 /// 写日志文件文件
    105 ///</summary>
    106 ///<param name="message">要写入的信息</param>
    107 public static void writeWithFile(string message)
    108 {
    109 writeWithFile(isWriteFile, defaultFileName, message);
    110 }
    111
    112 ///<summary>
    113 /// 写日志文件文件
    114 ///</summary>
    115 ///<param name="fileName">文件名</param>
    116 ///<param name="message">要写入的信息</param>
    117 public static void writeWithFile(string fileName, string message)
    118 {
    119 writeWithFile(isWriteFile, fileName, message);
    120 }
    121
    122 ///<summary>
    123 /// 写日志文件文件
    124 ///</summary>
    125 ///<param name="flag">是否写入</param>
    126 ///<param name="message">要写入的信息</param>
    127 public static void writeWithFile(bool flag, string message)
    128 {
    129 writeWithFile(flag, defaultFileName, message);
    130 }
    131
    132 ///<summary>
    133 /// 写日志文件文件
    134 ///</summary>
    135 ///<param name="flag">是否写入</param>
    136 ///<param name="fileName">文件名</param>
    137 ///<param name="message">写入信息</param>
    138 public static void writeWithFile(bool flag, string fileName, string message)
    139 {
    140 using (IsolatedStorageFile stroe = IsolatedStorageFile.GetUserStoreForApplication())
    141 {
    142 if (!stroe.FileExists(fileName))
    143 {
    144 using (System.IO.IsolatedStorage.IsolatedStorageFileStream isoFileStream = stroe.CreateFile(fileName))
    145 {
    146 System.IO.StreamWriter sw = new System.IO.StreamWriter(isoFileStream);
    147 sw.Write("{0} ------------- ", DateTime.Now.ToLongTimeString());
    148 sw.Write(message);
    149 sw.Close();
    150 }
    151 }
    152 else
    153 {
    154 using (System.IO.IsolatedStorage.IsolatedStorageFileStream isoFileStream = stroe.OpenFile(fileName, FileMode.Append))
    155 {
    156 System.IO.StreamWriter sw = new System.IO.StreamWriter(isoFileStream);
    157 sw.Write("\n{0} ------------- ", DateTime.Now.ToLongTimeString());
    158 sw.Write(message);
    159 sw.Close();
    160 }
    161 }
    162 }
    163 }
    164
    165 }
    166 }



  • 相关阅读:
    梯度下降在实践I -特征缩放
    多变量的梯度下降
    多个变量的线性回归
    线性回归的梯度下降
    梯度下降的直觉
    梯度下降
    洛谷P1087--FBI树(二叉树)
    二叉树入门(洛谷P1305)
    二叉树--已知先序中序求后序--已知中序后序求先序(基本按照网上某大神思路搬过来的)
    多边形面积(计算几何)
  • 原文地址:https://www.cnblogs.com/luxiaofeng54/p/2234964.html
Copyright © 2011-2022 走看看