我有以下具体的Serilog助手类和.Net 4.6.2 WPF应用程序:
public SerilogHelper()
{
Logger = CreateLogger();
}
private ILogger CreateLogger()
{
string levelString = Properties.Settings.Default.SerilogLevel;
SerilogLevel level = (SerilogLevel)Enum.Parse(typeof(SerilogLevel), levelString);
var levelSwitch = new LoggingLevelSwitch();
levelSwitch.MinimumLevel = (Serilog.Events.LogEventLevel)level;
string acName = Properties.Settings.Default.LoggingAccountName;
string acKey = Properties.Settings.Default.LoggingAccountKey;
Microsoft.WindowsAzure.Storage.Auth.StorageCredentials creds = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(acName, acKey);
Microsoft.WindowsAzure.Storage.CloudStorageAccount azureAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(creds, true);
return new LoggerConfiguration()
.MinimumLevel.ControlledBy(levelSwitch)
.WriteTo.File("log.txt", rollOnFileSizeLimit: true)
.WriteTo.AzureTableStorage(azureAccount)
.CreateLogger();
}
设置好东西后,我会调用辅助方法,如下所示:
public void WriteString(string content)
{
Logger.Debug(content);
}
我想创建一个方法来记录方法已经开始,它的名称和任何参数的值。因此,调用方法看起来像:
SerilogHelper.StartingMethod("My method name", params for my method)
有这样做的好方法吗?