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

            public static string LogPath
            {
                get
                {
                    string path = string.Empty;
                    path = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) +
                            @"\Microsoft Shared\web server extensions\12\LOGS\";
                    if (!Directory.Exists(path))
                    {
                        path = @"c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS\";
                    }
                    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}\r\n{1}\r\n\r\n", DateTime.Now, Message));
                                SW.Close();
                                SW.Dispose();
                                FS.Close();
                                FS.Dispose();
                            }
                        );
                }
                catch { }
                finally
                {
                    SW = null;
                    FS = null;
                }
            }
    
  • 相关阅读:
    stl-序列式容器
    BFS
    Hash
    二分法
    草稿1
    红黑树的左旋、右旋和颜色变换
    动态规划
    自动驾驶-安全
    二叉树

  • 原文地址:https://www.cnblogs.com/gzh4455/p/2235796.html
Copyright © 2011-2022 走看看