using NLog; using Sony.Filtr.Core.SpotifyCharts.Data; using Sony.Filtr.Utility.Extensions; using System; using System.Diagnostics; using System.Diagnostics.Tracing; namespace Sony.Filtr.Tasks.EventSource { public class ApolloFetchSpotifyChartsEventSource : System.Diagnostics.Tracing.EventSource { public static readonly ApolloFetchSpotifyChartsEventSource Log = new ApolloFetchSpotifyChartsEventSource(); private ApolloFetchSpotifyChartsEventSource() { } public void ProcessStart(int totalMarkets) { this.WriteEvent(1, totalMarkets); } [NonEvent] public void ProcessStop(Stopwatch sw, Logger logger) { sw.Stop(); logger.Warn($"Finished processing all markets. Duration: {sw.Elapsed.TotalMilliseconds} ms."); this.ProcessStop(); } private void ProcessStop() { this.WriteEvent(2); } public void MarketProcessStart(string market) { this.WriteEvent(3, market); } [NonEvent] public void MarketProcessStop(string market, Stopwatch sw, Logger logger) { sw.Stop(); //logger.Warn($"Market {market} processed. Duration: {sw.Elapsed.TotalMilliseconds} ms."); this.MarketProcessStop(market); } private void MarketProcessStop(string market) { this.WriteEvent(4, market); } public void SaveChartStart(SpotifyChartsListType listType, string market, SpotifyChartsTimeWindow timeWindow) { this.WriteEvent(5, market, listType.ToString(), timeWindow.ToString()); } [NonEvent] public void SaveChartStop(SpotifyChartsListType listType, string market, SpotifyChartsTimeWindow timeWindow, Stopwatch sw, Logger logger) { sw.Stop(); //logger.Warn($"Processed market: {market}. ListType: {listType}. TimeWindows: {timeWindow}. Duration: {sw.Elapsed.TotalMilliseconds} ms."); this.SaveChartStop(listType, market, timeWindow); } private void SaveChartStop(SpotifyChartsListType listType, string market, SpotifyChartsTimeWindow timeWindow) { this.WriteEvent(6, market, listType.ToString(), timeWindow.ToString()); } [NonEvent] public void SaveChartException(SpotifyChartsListType listType, string market, SpotifyChartsTimeWindow timeWindow, Stopwatch sw, Logger logger, Exception ex) { sw.Stop(); logger.Warn($"Processed with ERROR market: {market}. ListType: {listType}. TimeWindows: {timeWindow}. Duration: {sw.Elapsed.TotalMilliseconds} ms. ExceptionType: {ex.GetType().Name}. ExceptionMessage: {ex.GetFullMessage()}"); this.SaveChartException(listType, market, timeWindow, ex.GetType().Name, ex.GetFullMessage()); } private void SaveChartException(SpotifyChartsListType listType, string market, SpotifyChartsTimeWindow timeWindow, string exceptionType, string exceptionMessage) { this.WriteEvent(7, market, listType.ToString(), timeWindow.ToString(), exceptionType, exceptionMessage); } public void SaveChartDateStart(SpotifyChartsListType listType, string market, SpotifyChartsTimeWindow timeWindow, string date) { this.WriteEvent(8, market, listType.ToString(), timeWindow.ToString(), date); } [NonEvent] public void SaveChartDateStop(SpotifyChartsListType listType, string market, SpotifyChartsTimeWindow timeWindow, string date, Stopwatch sw, Logger logger) { sw.Stop(); //logger.Warn($"Processed date {date} market: {market}. ListType: {listType}. TimeWindows: {timeWindow}. Duration: {sw.Elapsed.TotalMilliseconds} ms."); this.SaveChartDateStop(listType, market, timeWindow, date); } private void SaveChartDateStop(SpotifyChartsListType listType, string market, SpotifyChartsTimeWindow timeWindow, string date) { this.WriteEvent(9, market, listType.ToString(), timeWindow.ToString(), date); } [NonEvent] public void SaveChartDateException(SpotifyChartsListType listType, string market, SpotifyChartsTimeWindow timeWindow, string date, Stopwatch sw, Logger logger, Exception ex) { sw.Stop(); logger.Warn($"Processed with ERROR date {date} market: {market}. ListType: {listType}. TimeWindows: {timeWindow}. Duration: {sw.Elapsed.TotalMilliseconds} ms. ExceptionType: {ex.GetType().Name}. ExceptionMessage: {ex.GetFullMessage()}"); this.SaveChartDateException(listType, market, timeWindow, date, ex.GetType().Name, ex.GetFullMessage()); } private void SaveChartDateException(SpotifyChartsListType listType, string market, SpotifyChartsTimeWindow timeWindow, string date, string exceptionType, string exceptionMessage) { this.WriteEvent(10, listType.ToString(), market, timeWindow.ToString(), date, exceptionType, exceptionMessage); } } }