ASP. NET calls dephi multi-thread log function

Source: Internet
Author: User

Although I don't know about dephi and multithreading, I don't know much about dephi, but it is still quite easy to use and secure. record logs are saved in a specific format and the specified software can be opened and written down.

Interface Class

Code
// C # Call 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;

// Call an unmanaged DLL. getchartfromxmlbynet is the name of the function exposed by chartaccess. dll.
[Dllimport ("log. dll", entrypoint = "set_save_path", charset = charset. ANSI, callingconvention = callingconvention. stdcall)]

// Set the Save path (D :\)
Public static extern void set_save_path (string path );

[Dllimport ("log. dll", entrypoint = "log_message", charset = charset. ANSI, callingconvention = callingconvention. stdcall)]

// Log information
Public static extern int log_message (INT code, intptr abuffer, int abuffersize );

[Dllimport ("log. dll", entrypoint = "log_error", charset = charset. ANSI, callingconvention = callingconvention. stdcall)]

// Log error message
Public static extern int log_error (INT code, intptr abuffer, int abuffersize );

[Dllimport ("log. dll", entrypoint = "save", charset = charset. ANSI, callingconvention = callingconvention. stdcall)]

// Save Method
Public static extern int save ();

[Dllimport ("log. dll", entrypoint = "set_active", charset = charset. ANSI, callingconvention = callingconvention. stdcall)]

// Whether to enable the log function
Public static extern int set_active (bool value );

 

ASP. NET implementation:

Code
Public class loginput
{

Public loginput ()
{
//
// Todo: add the constructor logic here
//
}

/// <Summary>
/// Set the Save path (D :\)
/// </Summary>
/// <Param name = "path"> </param>
Public static void set_save_path (string path ){
Drawchartfromdll. set_save_path (PATH );
}

/// <Summary>
/// Log information
/// </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>
/// Log error message
/// </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>
/// Save Method
/// </Summary>
Public static void save (){
Drawchartfromdll. Save ();
}

/// <Summary>
/// Whether to enable the log function
/// </Summary>
/// <Param name = "value"> </param>
Public static void set_active (bool value ){
Drawchartfromdll. set_active (value );
}
}

 

Call:

Code
PDL. Common. loginput. set_active (true );
PDL. Common. loginput. set_save_path (server. mappath ("\\"));
PDL. Common. loginput. log_message (0, "log function started ");
Response. Write ("START success ");

PDL. Common. loginput. log_message (0, "log function disabled ");
PDL. Common. loginput. Save ();
PDL. Common. loginput. set_active (false );
Response. Write ("Shut success ");
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.