Ejemplo n.º 1
0
        /// <summary>
        /// This method is called from the CoreLibs and passed to managed code
        /// </summary>
        /// <param name="attachment">Pointer to the native logger</param>
        /// <param name="logLevel">Log level</param>
        /// <param name="pMessage">Pointer to the log message</param>
        /// <param name="length">Message length</param>
        private static void AGOnDnsLogged(
            IntPtr attachment,
            AGDnsApi.ag_log_level logLevel,
            IntPtr pMessage,
            UInt32 length)
        {
            try
            {
                LogBylogLevel          logByLogLevel = LOG_LEVELS_MAPPING[logLevel];
                MarshalUtils.ag_buffer agBuffer      = new MarshalUtils.ag_buffer
                {
                    data = pMessage,
                    size = length
                };

                string message = MarshalUtils.AgBufferToString(agBuffer);
                // We have to forcibly trim trailing CR due to
                // https://bit.adguard.com/projects/ADGUARD-CORE-LIBS/repos/dns-libs/pull-requests/306/diff#platform/windows/capi/include/ag_dns.h
                message = message.TrimEnd(Environment.NewLine.ToCharArray());
                logByLogLevel(message);
            }
            catch (Exception ex)
            {
                DnsExceptionHandler.HandleManagedException(ex);
            }
        }