我在構造函數鏈中看到了答案,但它們不適用於我的問題。執行代碼後調用構造函數的C#構造函數
我有下面的構造函數,需要幾個參數:
public SerilogHelper(string conString, int minLevel)
{
var levelSwitch = new LoggingLevelSwitch();
levelSwitch.MinimumLevel = (Serilog.Events.LogEventLevel)(Convert.ToInt32(minLevel));
_logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(levelSwitch)
.WriteTo.MSSqlServer(connectionString: conString,
tableName: "Logs",
autoCreateSqlTable: true)
.CreateLogger();
}
此構造不會對參數所需的值的一個特定的客戶端,所以我希望能夠調用這個簡單的構造函數,會得到所需的值,然後撥打第一個構造函數:
public SerilogHelper()
{
string minLevel = SSOSettingsFileManager.SSOSettingsFileReader.ReadString(
"LCC.Common", "serilog.level");
string conString = SSOSettingsFileManager.SSOSettingsFileReader.ReadString(
"LCC.Common", "serilog.connectionstring");
SerilogHelper(conString, minLevel);
}
問題是,我得到一個紅色波浪上的呼叫與消息SerilogHelper 2號構造是一個「型」,但一樣使用一個 '變量'
[C#構造超載]的可能的複製(https://stackoverflow.com/questions/5555715/c-sharp-constructors-overloading) – Liam