-
Notifications
You must be signed in to change notification settings - Fork 0
/
SFLOG.cs
149 lines (127 loc) · 6.7 KB
/
SFLOG.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#region License
// <copyright file="SFLogger.cs" company="Spider Financial Corp">
// (c) 2007-2014 Spider Financial Corp.
// All rights reserved.
// </copyright>
//
//
#endregion
#region Using Directives
using System;
using System.Runtime.InteropServices;
using System.Linq.Expressions;
#endregion
namespace NumXLAPI
{
/// <summary>
/// SFLOG_LEVEL defines the supported log levels
/// </summary>
public enum SFLOG_LEVEL
{
/// <summary> All messages </summary>
SFLOG_ALL=0,
/// <summary> All logging messages including trace messages </summary>
SFLOG_TRACE=1,
/// <summary> debug, info, warning, error and fatal messages </summary>
SFLOG_DEBUG=2,
/// <summary> info, warning, error and fatal messages </summary>
SFLOG_INFO=3,
/// <summary> warning, error and fatal messages </summary>
SFLOG_WARN=4,
/// <summary> error and fatal messages </summary>
SFLOG_ERROR=5,
/// <summary> fatal messages </summary>
SFLOG_FATAL=6,
/// <summary> logging is off, no log messages is written to the log-file </summary>
SFLOG_OFF=7
}
/// <summary>
/// Warpper class for C-API in SFLOG.dll.
/// Add logging functionality to a log4j-type text file.
/// </summary>
public class SFLOG
{
private const string DLLName = "SFLog.dll";
/// <summary> Initialize the logging system. </summary>
/// <param name="szAppName">Application name (e.g. NumXL).</param>
/// <param name="szLogDir">Temprorary directory to use for storing logging file and intermediate files.</param>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#100",CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int SFLOG_Init(string szAppName, string szLogDir);
/// <summary>
/// Wrap the NDK_INIT API function with a CLS compliant function
/// </summary>
/// <param name="szAppName"></param>
/// <param name="szLogDir"></param>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
public static NDK_RETCODE Init(string szAppName, string szLogDir)
{
int nRet = SFLOG_Init(szAppName, szLogDir);
return (NDK_RETCODE)nRet;
}
/// <summary> Shutdown and release any resouces used by the logging system. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#105",CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int SFLOG_Shutdown();
/// <summary>
/// Wrap the NDK_Shutdown API function with a CLS compliant function
/// </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
public static NDK_RETCODE Shutdown()
{
int nRet = SFLOG_Shutdown();
return (NDK_RETCODE)nRet;
}
/// <summary> Log a message to the log-file. </summary>
/// <param name="nLevel">Logging level <see cref="SFLOG_LEVEL"/>.</param>
/// <param name="szFilename">current source filename.</param>
/// <param name="szFuncName">the function from which the method is called.</param>
/// <param name="szFuncSig">the full function signature from which the method is called.</param>
/// <param name="nLineNo">the line number where the log function is called from.</param>
/// <param name="szMsg">the actual logging message.</param>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#110", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int SFLOG_LogMsg(int nLevel, string szFilename, string szFuncName,
string szFuncSig, int nLineNo, string szMsg);
/// <summary>
/// Wrap the SFLOG_LogMsg API function with a CLS compliant function. </summary>
/// <param name="nLevel">Logging level <see cref="SFLOG_LEVEL"/>.</param>
/// <param name="szFilename">current source filename.</param>
/// <param name="szFuncName">the function from which the method is called.</param>
/// <param name="szFuncSig">the full function signature from which the method is called.</param>
/// <param name="nLineNo">the line number where the log function is called from.</param>
/// <param name="szMsg">the actual logging message.</param>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
public static NDK_RETCODE LogMsg(SFLOG_LEVEL nLevel, string szFilename, string szFuncName, string szFuncSig, int nLineNo, string szMsg)
{
int nRet = SFLOG_LogMsg((int)nLevel, szFilename, szFuncName, szFuncSig, nLineNo, szMsg);
return (NDK_RETCODE)nRet;
}
/// <summary> Returns current logging level. </summary>
/// <param name="nLevel">current logging level <see cref="SFLOG_LEVEL"/>.</param>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#115", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int SFLOG_GETLEVEL(out int nLevel);
/// <summary> query the current logging level in the SDK. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="SFLOG_LEVEL"/>.</returns>
public static SFLOG_LEVEL GETLEVEL()
{
int nLevel = (int)SFLOG_LEVEL.SFLOG_ALL;
int nRet = SFLOG_GETLEVEL(out nLevel);
return (SFLOG_LEVEL)nLevel;
}
/// <summary> Modify current logging level. </summary>
/// <param name="nLevel">new logging level <see cref="SFLOG_LEVEL"/>.</param>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#120", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int SFLOG_SETLEVEL(int nLevel);
/// <summary> set the new logging level in the SDK. </summary>
/// <param name="nLevel">new logging level <see cref="SFLOG_LEVEL"/>.</param>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
public static NDK_RETCODE SETLEVEL(SFLOG_LEVEL nLevel)
{
int nRet = SFLOG_SETLEVEL((int)nLevel);
return (NDK_RETCODE)nRet;
}
}
}