zoukankan      html  css  js  c++  java
  • 工具类:Log

    public static string LogPath
    {
        get
        {
            string path = string.Empty;
            path = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) +
                    @"Microsoft Sharedweb server extensions12LOGS";
            if (!Directory.Exists(path))
            {
                path = @"c:Program FilesCommon FilesMicrosoft Sharedweb server extensions12LOGS";
            }
            return path;
        }
    }
     
    public static void Write(string Message)
    {
        FileStream FS = null;
        StreamWriter SW = null;
        try
        {
            SPSecurity.RunWithElevatedPrivileges
                (
                    delegate
                    {
                        FS = File.Open(
                            string.Format(
                            "{0}PosterscopeUSA Notification-{1}-{2}-{3}.log",
                            LogPath, 
                            DateTime.Now.Year,
                            DateTime.Now.Month,
                            DateTime.Now.Day),
                            FileMode.Append);
                        SW = new StreamWriter(FS);
                        SW.Write(string.Format("{0}
    {1}
    
    ", DateTime.Now, Message));
                        SW.Close();
                        SW.Dispose();
                        FS.Close();
                        FS.Dispose();
                    }
                );
        }
        catch { }
        finally
        {
            SW = null;
            FS = null;
        }
    }
    

      

  • 相关阅读:
    事件基础
    DOM
    GoWeb编程之多路复用
    GoWeb编程之HelloWorld
    Linux libtins 库安装教程
    模式串匹配KMP详解
    树的重心
    Light OJ 1064
    Light OJ 1060
    1057
  • 原文地址:https://www.cnblogs.com/batter152/p/4244012.html
Copyright © 2011-2022 走看看