public static CreateNativeStr ( string str, |
||
str | string | the managed string object |
nativeLen | native string length | |
appendNull | bool | auto append \0 character option, default is true |
리턴 |
/// <summary> /// Load ini config data from ini format string content. /// </summary> /// <param name="content">ini format string content</param> public void LoadFromContent(string content) { _sections.Clear(); unsafe { int sectionCount = 0; IntPtr nativeContent = LibUtil.CreateNativeStr(content); int errDescLen = 0; IntPtr nativeSections = LLBCNative.csllbc_Ini_LoadFromContent(nativeContent, new IntPtr(§ionCount), new IntPtr(&errDescLen)); LibUtil.FreeNativePtr(ref nativeContent, false); if (sectionCount == -1) { byte * nativeErrorDesc = (byte *)nativeSections; string errorDesc = LibUtil.Ptr2Str(nativeErrorDesc, errDescLen); LibUtil.FreeNativePtr(nativeErrorDesc); throw new LLBCException("{0}", errorDesc); } else if (sectionCount == 0) { return; } _LoadAllSections((_NativeIniSection *)nativeSections.ToPointer(), sectionCount); LLBCNative.csllbc_Ini_FreeNativeSections(nativeSections, sectionCount); } }
private void _Log(object tag, LogLevel level, int skipFrames, string fmt, params object[] args) { if (!enabled) { return; } IntPtr fileName = IntPtr.Zero; // Get filename, lineno, if enabled. int lineNo = -1; if (_enabledLogFileInfo) { var st = new System.Diagnostics.StackTrace(true); var frame = st.GetFrame(skipFrames); lineNo = frame.GetFileLineNumber(); fileName = LibUtil.CreateNativeStr(frame.GetFileName()); } IntPtr nativeTag = IntPtr.Zero; IntPtr nativeMsg = IntPtr.Zero; try { // Get log tag. if (tag is Type) { nativeTag = LibUtil.CreateNativeStr((tag as Type).Name); } else if (tag != null) { nativeTag = LibUtil.CreateNativeStr(tag.ToString()); } // Build log message. nativeMsg = LibUtil.CreateNativeStr(string.Format(fmt, args)); LLBCNative.csllbc_Log_LogMsg(_nativeLogger, fileName, lineNo, (int)level, nativeMsg, nativeTag); } catch (Exception e) { // Firstly, free nativeMsg. System.Runtime.InteropServices.Marshal.FreeHGlobal(nativeMsg); // Simply format error message and dump it. string errMsg = string.Format("Log [{0}] failed, exception:{1}, stacktrace:\n{2}", fmt, e.Message, new System.Diagnostics.StackTrace().ToString()); nativeMsg = LibUtil.CreateNativeStr(errMsg); LLBCNative.csllbc_Log_LogMsg(_nativeLogger, fileName, lineNo, (int)LogLevel.Fatal, nativeMsg, nativeTag); } finally { System.Runtime.InteropServices.Marshal.FreeHGlobal(nativeTag); System.Runtime.InteropServices.Marshal.FreeHGlobal(nativeMsg); } System.Runtime.InteropServices.Marshal.FreeHGlobal(fileName); }
public Logger(string loggerName) { _loggerName = loggerName; IntPtr nativeLoggerName = LibUtil.CreateNativeStr(_loggerName); _nativeLogger = LLBCNative.csllbc_Log_GetLogger(nativeLoggerName); System.Runtime.InteropServices.Marshal.FreeHGlobal(nativeLoggerName); if (_nativeLogger == IntPtr.Zero) { throw ExceptionUtil.CreateExceptionFromCoreLib(); } }
/// <summary> /// Initialize Log. /// </summary> /// <param name="logCfgFile">log config file</param> public static void Init(string logCfgFile) { if (string.IsNullOrEmpty(logCfgFile)) { throw new LLBCException("please specific log config file"); } lock (_lock) { IntPtr nativeStr = LibUtil.CreateNativeStr(logCfgFile); int ret = LLBCNative.csllbc_Log_Init(nativeStr); System.Runtime.InteropServices.Marshal.FreeHGlobal(nativeStr); if (ret != LLBCNative.LLBC_OK) { throw ExceptionUtil.CreateExceptionFromCoreLib(); } _rootLogger = Get("root"); } }