NTP Analyzer  0.8.2
Analyze the operation of time servers
LogExtensions.cs
Go to the documentation of this file.
1 //
2 // Copyright (c) 2013-2017 Carsten Sonne Larsen <cs@innolan.net>
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21 
22 using System;
23 using Ntp.Common.Log;
24 
25 namespace Ntp.Analyzer.Data.Log
26 {
27  internal static class LogMessages
28  {
29  internal const string DatabaseCacheError = "Mapper does not implement caching.";
30  internal const string DatabaseNoUpdate = "Updating rows in {0} table is not supported.";
31  }
32 
33  internal static class LogExtensions
34  {
35  internal static void CreateDatabaseError(this LogBase log, Exception e)
36  {
37  log.WriteLine("Failed to create database.", Severity.Error);
38  log.WriteLine(e);
39  }
40 
41  internal static void CreateTable(this LogBase log, string table)
42  {
43  log.WriteLine(
44  $"Creating new table '{table}'.",
45  Severity.Notice);
46  }
47 
48  internal static void CreateTableError(this LogBase log, Exception e)
49  {
50  log.WriteLine("Could not create database table.", Severity.Error);
51  log.WriteLine(e);
52  }
53 
54  internal static void DeleteError(this LogBase log, string table, Exception e)
55  {
56  log.WriteLine($"Error while deleting from table {table}: {e.Message}", Severity.Warn);
57  log.WriteLine(e, Severity.Warn);
58  Advice(log);
59  }
60 
61  internal static void InsertError(this LogBase log, string table, Exception e)
62  {
63  log.WriteLine($"Error while inserting into table {table}: {e.Message}", Severity.Warn);
64  log.WriteLine(e, Severity.Warn);
65  Advice(log);
66  }
67 
68  internal static void ReadError(this LogBase log, string table, Exception e)
69  {
70  log.WriteLine($"Error while reading from table {table}: {e.Message}", Severity.Warn);
71  log.WriteLine(e, Severity.Warn);
72  Advice(log);
73  }
74 
75  internal static void TableExists(this LogBase log, string table)
76  {
77  log.WriteLine(
78  $"Skipping table '{table}'. Already exist.",
79  Severity.Debug);
80  }
81 
82  internal static void UpdateError(this LogBase log, string table, Exception e)
83  {
84  log.WriteLine($"Error while updating table {table}: {e.Message}", Severity.Warn);
85  log.WriteLine(e, Severity.Warn);
86  Advice(log);
87  }
88 
89  private static void Advice(LogBase log)
90  {
91  log.WriteLine("Please check your configuration.", Severity.Notice);
92  }
93  }
94 
95  internal static class LogMessagesImport
96  {
97  internal static void TimeServerDownload(this LogBase log, string provider, string url, int orgId)
98  {
99  log.WriteLine($"Fetching data from {provider} for server ID {orgId}", Severity.Info);
100  log.WriteLine($"Downloading ... {url}", Severity.Debug);
101  }
102 
103  internal static void TimeServerError(this LogBase log, string provider, int orgId)
104  {
105  log.WriteLine($"Error while contacting {provider} with ID {orgId}", Severity.Warn);
106  }
107 
108  internal static void TimeServerFetchError(this LogBase log, Exception e)
109  {
110  log.WriteLine("Failed to fetch time server data.", Severity.Warn);
111  log.WriteLine(e, Severity.Warn);
112  }
113 
114  internal static void TimeServerMaxId(this LogBase log, string provider)
115  {
116  log.WriteLine($"Not contacting {provider} for ID > 10000.", Severity.Debug);
117  }
118 
119  internal static void TimeServerNotFound(this LogBase log, string provider, int orgId)
120  {
121  log.WriteLine($"Time server not found at {provider}. ID: {orgId}", Severity.Info);
122  }
123 
124  internal static void TimeServerNotReceived(this LogBase log, int orgId)
125  {
126  log.WriteLine($"Nothing received for time server ID {orgId}.", Severity.Debug);
127  }
128 
129  internal static void TimeServerParseError(this LogBase log, string type, Exception e)
130  {
131  log.WriteLine($"Could not parse time server {type}.", Severity.Warn);
132  log.WriteLine(e, Severity.Warn);
133  }
134  }
135 }
static void TimeServerNotReceived(this LogBase log, int orgId)
static void InsertError(this LogBase log, string table, Exception e)
abstract void WriteLine(string text, Severity severity)
static void CreateTableError(this LogBase log, Exception e)
static void ReadError(this LogBase log, string table, Exception e)
static void TimeServerDownload(this LogBase log, string provider, string url, int orgId)
static void TimeServerParseError(this LogBase log, string type, Exception e)
static void TimeServerError(this LogBase log, string provider, int orgId)
static void Advice(LogBase log)
var e
Definition: bootstrap.min.js:6
static void UpdateError(this LogBase log, string table, Exception e)
static void TimeServerNotFound(this LogBase log, string provider, int orgId)
static void TableExists(this LogBase log, string table)
static void TimeServerMaxId(this LogBase log, string provider)
static void CreateDatabaseError(this LogBase log, Exception e)
static void TimeServerFetchError(this LogBase log, Exception e)
static void DeleteError(this LogBase log, string table, Exception e)
static void CreateTable(this LogBase log, string table)