2

I premit that I'm quite new to Anotar / Serilog, I've my WPF application that uses the Repository Pattern and I've the repo strucured as

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);
    }

Right now I was logging in the viewmodels as

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

I was wondering if there's an Attribute that I can apply to a class in order to automatically log the Method and the parameters.

Right now my logged is configured as

 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;

Thanks

advapi
  • 3,661
  • 4
  • 38
  • 73

1 Answers1

0

You can get the method name and line number by adding {Method} and {LineNumber} to the output template respectively.

As far as I know, there is no way to automatically log the parameters; you would need to do this manually.

Chris Haines
  • 6,445
  • 5
  • 49
  • 62