c# - F# 脚本调用 C# exe 时的 log4net 问题

标签 c# f# log4net

我有一个写 log4net 日志的 C# exe。如果我直接运行这个 exe,日志记录工作正常。 但是,如果我从 F# 脚本(扩展名为 fsx)调用 exe,则会出现错误

log4net:ERROR Failed to find configuration section 'log4net' in the application'
s .config file. Check your .config file for the <log4net> and <configSections> e
lements. The configuration section should look like: <section name="log4net" typ
e="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

有人可以帮忙吗?非常感谢

最佳答案

您应该将此 exe 文件的配置插入到您的 f# 应用程序的配置文件或在代码中初始化记录器。我不确定当您运行 f# 脚本时是否有配置文件。

您可以尝试使用以下代码将配置设置为您的 c# exe 的配置文件:

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "c:/test.config);

关于c# - F# 脚本调用 C# exe 时的 log4net 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13749807/

相关文章:

c# - 在.net webApi中删除没有id参数的请求

c# - 带有 AdoNetAppender 的 Log4Net - 没有任何反应

c# - 如何在 .config 文件中设置 log4net SmtpAppender 发件人名称

c# - Log4net - 使用继承时的最佳策略

c# - 如何通过契约(Contract)定义 IEnumerable 行为?

c# - 在 SET 子句中多次指定列名 'phoneNumber'

c# - Linq 嵌套列表 3 深

f# - 如何在 F# 中将列表的两个第 n 个元素相乘

f# - 在 F# 中将序列包装在流中

macos - FSharp.Charting.Gtk 在启动时崩溃