2015-11-26 57 views
2

我premit我是很新的Anotar/Serilog,我已經在我的WPF應用程序,使用存儲庫模式,我已經回購眼下strucured作爲Anotar.Serilog和記錄

public class CalendarRepository : DefaultRepositoryBase, ICalendarRepository 
{ 
    public Task<IList<CalendarTemplate>> GetCalendarTemplatesAsync(int? template) 
    { 
     JsonServiceClient client = GetServiceStackClient(); 

     var request = new CalendarTemplatesRequest 
     { 
      Template = template 
     }; 
     return client.PostAsync(request); 
    } 

    public Task<IList<Currency>> GetCurrenciesAsync(int? currency) 
    { 
     JsonServiceClient client = GetServiceStackClient(); 

     var request = new CurrenciesRequest 
     { 
      Currency = currency 
     }; 
     return client.PostAsync(request); 
    } 

    public Task<IList<CurrencyCalendar>> GetCurrencyCalendarsAsync(IEnumerable<int> currencies) 
    { 
     JsonServiceClient client = GetServiceStackClient(); 

     var request = new CurrencyCalendarsRequest 
     { 
      Currencies = currencies 
     }; 
     return client.PostAsync(request); 
    } 

我在被的ViewModels登錄爲

LogTo.Information("Getting calendar currencies {SelectedCurrencies}",selectedCurrenciesId.Select(x=>x.Id)); 
       var items = await repository.GetCurrencyCalendarsAsync(selectedCurrenciesId.Select(x => x.Id)); 

我在想,如果有,我可以適用於一類,以便自動記錄方法和參數的屬性。

現在我記錄的配置爲

var log = 
      new LoggerConfiguration().MinimumLevel.ControlledBy(
       levelSwitch: new LoggingLevelSwitch(LogEventLevel.Debug)).WriteTo.File(@".\logs\serilog.log",outputTemplate: "{Timestamp: yyyy-MM-dd HH:mm:ss.fff} [{Level}] [{SourceContext}] {Message}{NewLine}{Exception}").CreateLogger(); 

     Serilog.Log.Logger = log; 

感謝

+0

這將是非常有益的。 – pkidza

回答

0

您可以通過添加分別的方法{}和{} LineNumber上的輸出模板獲得方法名和行號。

據我所知,沒有辦法自動記錄參數;您需要手動執行此操作。