在 .NET Core 控制台应用程序中从 C# 调用 MacOS 的 os_log 的语法应该是什么?
基于
https://developer.apple.com/documentation/os/os_log
和
如何将 iOS OSLog 与 Xamarin 一起使用?
和
https://opensource.apple.com/source/xnu/xnu-4903.221.2/libkern/os/log.h.auto.html
我期待这样的事情:
using System.Runtime.InteropServices;
namespace Foo
{
class Program
{
[DllImport("__Internal", EntryPoint = "os_log_create")]
private static extern IntPtr os_log_create(string subsystem, string category);
[DllImport("__Internal", EntryPoint = "os_log")]
private static extern void os_log(IntPtr log, string format, string message);
static void Main(string[] args)
{
IntPtr log = os_log_create("some.bundle.id", "SomeCategory");
os_log(log, "%s", "Test!");
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在我的 Mac 上运行它时,我得到一个System.DllNotFoundException说Unable to …
我在 MacOS 上的 .NET Core 中有一个 (C#) 控制台应用程序。
\n\n\xc2\xa0
\n\n如何获取当前用户名?
\n\n\xc2\xa0
\n\n我试过
\n\n环境.GetEnvironmentVariable(“用户”);
\n\n和
\n\n环境.GetEnvironmentVariable(“用户名”);
\n\n但我什么也没得到。
\n\n我想getpwuid()根据此处描述的提示尝试 P/Invoke:\xc2\xa0
/sf/answers/1318942061/ \xc2\xa0
\n\n但我不确定该passwd结构的 C# 语法应该是什么。
对此表示赞赏的任何帮助,以及 P/Invoke 上资源的任何指示都可以帮助我了解 P/Invoke 从 .NET Core 到 MacOS 本机代码的诀窍。
\n