ASP.NET調用Dephi多線程日誌功能

來源:互聯網
上載者:User

雖然對Dephi不瞭解,對多線程也不太瞭解,但是這個還比較好用,安全性也不錯,記錄日誌用特定格式儲存,指定的軟體才能開啟,記下了。

介面類

Code
//c#調用Dephi
    public static class DrawChartFromDll
    {
        //function set_save_path(aDir : PChar) : Cardinal; stdcall;
        //function log_message(aCode : integer; aBuffer : pointer; aBufferSize: DWORD) : Cardinal; stdcall;
        //function log_error(aCode : integer; aBuffer : pointer; aBufferSize: DWORD) : Cardinal; stdcall;
        //function save: Cardinal; stdcall;
        //function set_active(aValue : LongBool): Cardinal; stdcall;

        //調用非託管Dll,GetChartFromXMLByNet是ChartAccess.dll公開的函數名稱 
        [DllImport("log.dll", EntryPoint = "set_save_path", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]

        //設定儲存路徑 (D:\)
        public static extern void set_save_path(string path);

        

        [DllImport("log.dll", EntryPoint = "log_message", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]

        //日誌資訊
        public static extern int log_message(int Code, IntPtr aBuffer, int aBufferSize);

        [DllImport("log.dll", EntryPoint = "log_error", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]

        //日誌錯誤資訊
        public static extern int log_error(int Code, IntPtr aBuffer, int aBufferSize);

        [DllImport("log.dll", EntryPoint = "save", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]

        //儲存方法
        public static extern int save();

        [DllImport("log.dll", EntryPoint = "set_active", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]

        //是否開機記錄功能
        public static extern int set_active(bool value);

 

 ASP.NET實現:

Code
public class LogInput
    {

        public LogInput()
        {
            //
            // TODO: 在此處添加建構函式邏輯
            //
        }

        /// <summary>
        /// 設定儲存路徑 (D:\)
        /// </summary>
        /// <param name="path"></param>
        public static void set_save_path(string path) {
            DrawChartFromDll.set_save_path(path);
        }

        /// <summary>
        /// 日誌資訊
        /// </summary>
        /// <param name="Code"></param>
        /// <param name="message"></param>
        public static void log_message(int Code, string message)
        {
            DrawChartFromDll.log_message(Code, Marshal.StringToHGlobalAnsi(message), System.Text.Encoding.Default.GetByteCount(message));
        }

        /// <summary>
        /// 日誌錯誤資訊
        /// </summary>
        /// <param name="Code"></param>
        /// <param name="message"></param>
        public static void log_error(int Code, string message)
        {
            DrawChartFromDll.log_message(Code, Marshal.StringToHGlobalAnsi(message), System.Text.Encoding.Default.GetByteCount(message));
        }

        /// <summary>
        /// 儲存方法
        /// </summary>
        public static void save() {
            DrawChartFromDll.save();
        }

        /// <summary>
        /// 是否開機記錄功能
        /// </summary>
        /// <param name="value"></param>
        public static void set_active(bool value) {
            DrawChartFromDll.set_active(value);
        }
    }

 

調用:

Code
PDL.Common.LogInput.set_active(true);
PDL.Common.LogInput.set_save_path(Server.MapPath("\\"));
PDL.Common.LogInput.log_message(0, "日誌功能啟動");
Response.Write("Start Success");
                    
PDL.Common.LogInput.log_message(0, "日誌功能關閉");
PDL.Common.LogInput.save();
PDL.Common.LogInput.set_active(false);
Response.Write("Shut Success");

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.