public override void Write(string message, RoggleLogLevel level) { var newEvent = new OverseerEvent() { Description = message, Name = Source, UserId = Key, Level = level == RoggleLogLevel.Critical ? OverseerEventLevel.Critical : level == RoggleLogLevel.Debug ? OverseerEventLevel.Debug : level == RoggleLogLevel.Error ? OverseerEventLevel.Error : level == RoggleLogLevel.Info ? OverseerEventLevel.Information : level == RoggleLogLevel.Warning ? OverseerEventLevel.Warning : OverseerEventLevel.Debug }; using (var client = new HttpClient()) { client.BaseAddress = new Uri(Url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = AsyncHelper.RunSync(() => client.PostAsJsonAsync("api/events", newEvent)); if (!response.IsSuccessStatusCode) { throw new RoggleException($"Overseer return an error '{response.StatusCode}: {response.ReasonPhrase}'."); } } }
public override void Write(string message, RoggleLogLevel level) { try { var newEvent = new OverseerEvent() { Description = message, Name = Source, UserId = Key, Level = level == RoggleLogLevel.Critical ? OverseerEventLevel.Critical : level == RoggleLogLevel.Debug ? OverseerEventLevel.Debug : level == RoggleLogLevel.Error ? OverseerEventLevel.Error : level == RoggleLogLevel.Info ? OverseerEventLevel.Information : level == RoggleLogLevel.Warning ? OverseerEventLevel.Warning : OverseerEventLevel.Debug }; using (var client = new HttpClient()) { client.BaseAddress = new Uri(Url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = AsyncHelper.RunSync(() => client.PostAsJsonAsync("api/events", newEvent)); if (!response.IsSuccessStatusCode) { throw new RoggleException($"Overseer return an error '{response.StatusCode}: {response.ReasonPhrase}'."); } } } catch (Exception e) { try { // Try to write a overseer.log var content = $"Something goes wrong while trying to log to Overseer: {e.Message}.{Environment.NewLine}" + $"RoggleOverseer wanted to write the following error:{Environment.NewLine}" + $"{Source} - {message}"; File.WriteAllText("overseer.log", content); } catch { // Nothing else to do ... } } }