【发布时间】:2023-03-30 01:48:01
【问题描述】:
我在.net框架类库项目中有这段代码,我想在.net标准类库项目中重用它。它按预期工作,但在 .net 标准项目中出现编译错误。
public FxLogger(string logger)
{
ILog AppLogger = LogManager.GetLogger(logger);
错误:
CS1503 Argument 1: cannot convert from 'string' to 'System.Type'
两个应用程序中的 log4net 版本 2.0.8
我可以在LogManager 类中看到这些方法声明
public static ILog GetLogger(string repository, string name);
public static ILog GetLogger(Assembly repositoryAssembly, Type type);
public static ILog GetLogger(string repository, Type type);
public static ILog GetLogger(Type type);
public static ILog GetLogger(Assembly repositoryAssembly, string name);
【问题讨论】:
-
唯一接受单个参数的重载是需要一个类型参数。
-
@MaxSzczurek 是的,我可以看到,但是我有一个字符串,我需要将其转换为
Type,什么类型?以及如何? -
您希望
LogManager.GetLogger("vivek nuna")会发生什么?还是任何其他字符串值? -
@AlexeiLevenkov 它是
LogManager.GetLogger(string.Empty) -
What to what type and how?你能描述一下吗?正如@AlexeiLevenkov 所说,当你通过LogManager.GetLogger(string.Empty)时你想要什么预期的行为
标签: c# log4net .net-standard log4net-configuration