我 P/调用一个 C 函数 (
fprintf
),它将一些文本打印到标准输出,但我无法像 Console.Writeline("text")
那样在 C# 应用程序的输出中看到此文本。
我在Windows下。
我需要做一些特别的事情才能获得
fprintf
输出吗?
public static unsafe System.Int32 AeronDriverContextSetPrintConfiguration(System.IntPtr context, System.Boolean value)
{
System.Byte value_;
System.Int32 __result__;
value_ = (System.Byte)(value ? 1 : 0);
__result__ = aeron_driver_context_set_print_configuration_((void *)context, value_);
return __result__;
}
internal static class Program
{
private IntPtr _ctx;
public static void Main()
{
if (AeronDriverContextInit(out _ctx) < 0)
throw new MediaDriverException($"AeronDriverContextInit: ({AeronErrcode()}) {AeronErrmsg()}");
AeronDriverContextSetPrintConfiguration(_ctx, true);
// I don't put the whole code, but here I start the driver etc
}
}
C 代码:
void aeron_driver_context_print_configuration(aeron_driver_context_t *context)
{
FILE *fpout = stdout;
char buffer[1024];
fprintf(fpout, "aeron_driver_context_t {");
fprintf(fpout, "\n cnc_version=%d.%d.%d",
(int)aeron_semantic_version_major(AERON_CNC_VERSION),
(int)aeron_semantic_version_minor(AERON_CNC_VERSION),
(int)aeron_semantic_version_patch(AERON_CNC_VERSION));
fprintf(fpout, "\n aeron_dir=%s", context->aeron_dir);
fprintf(fpout, "\n driver_timeout_ms=%" PRIu64, context->driver_timeout_ms);
}
github 项目的自述文件显示了如何启用日志记录:
https://github.com/real-logic/aeron/blob/master/aeron-driver/src/main/c/README.md
C 媒体驱动程序使用 DL 拦截来记录日志。要使用此日志记录,请将 Aeron C 驱动程序代理库添加到 LD_PRELOAD 或 DYLD_INSERT_LIBRARIES(对于 Mac。还需要平面命名空间),并将环境变量 AERON_EVENT_LOG 设置为感兴趣事件的数字掩码。为了方便起见,可以使用以下脚本。