|
| 1 | +/* |
| 2 | + _ _ _ ____ _ _____ |
| 3 | + / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ |
| 4 | + / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ |
| 5 | + / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | |
| 6 | +/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| |
| 7 | +
|
| 8 | + Copyright 2015-2016 Łukasz "JustArchi" Domeradzki |
| 9 | + |
| 10 | +
|
| 11 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 12 | + you may not use this file except in compliance with the License. |
| 13 | + You may obtain a copy of the License at |
| 14 | +
|
| 15 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 16 | + |
| 17 | + Unless required by applicable law or agreed to in writing, software |
| 18 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 19 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 | + See the License for the specific language governing permissions and |
| 21 | + limitations under the License. |
| 22 | +
|
| 23 | +*/ |
| 24 | + |
| 25 | +using System; |
| 26 | +using System.Diagnostics; |
| 27 | +using System.Runtime.CompilerServices; |
| 28 | +using System.Windows.Forms; |
| 29 | + |
| 30 | +namespace GUI { |
| 31 | + internal static class Logging { |
| 32 | + internal static void LogGenericInfo(string message) { |
| 33 | + if (string.IsNullOrEmpty(message)) { |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + MessageBox.Show(message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); |
| 38 | + } |
| 39 | + |
| 40 | + internal static void LogGenericWTF(string message, [CallerMemberName] string previousMethodName = "") { |
| 41 | + if (string.IsNullOrEmpty(message)) { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + MessageBox.Show(previousMethodName + "() " + message, "WTF", MessageBoxButtons.OK, MessageBoxIcon.Error); |
| 46 | + } |
| 47 | + |
| 48 | + internal static void LogGenericError(string message, [CallerMemberName] string previousMethodName = "") { |
| 49 | + if (string.IsNullOrEmpty(message)) { |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + MessageBox.Show(previousMethodName + "() " + message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); |
| 54 | + } |
| 55 | + |
| 56 | + internal static void LogGenericException(Exception exception, [CallerMemberName] string previousMethodName = "") { |
| 57 | + if (exception == null) { |
| 58 | + return; |
| 59 | + } |
| 60 | + |
| 61 | + MessageBox.Show(previousMethodName + "() " + exception.Message + Environment.NewLine + exception.StackTrace, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); |
| 62 | + |
| 63 | + if (exception.InnerException != null) { |
| 64 | + LogGenericException(exception.InnerException, previousMethodName); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + internal static void LogGenericWarning(string message, [CallerMemberName] string previousMethodName = "") { |
| 69 | + if (string.IsNullOrEmpty(message)) { |
| 70 | + return; |
| 71 | + } |
| 72 | + |
| 73 | + MessageBox.Show(previousMethodName + "() " + message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
| 74 | + } |
| 75 | + |
| 76 | + internal static void LogNullError(string nullObjectName, [CallerMemberName] string previousMethodName = "") { |
| 77 | + if (string.IsNullOrEmpty(nullObjectName)) { |
| 78 | + return; |
| 79 | + } |
| 80 | + |
| 81 | + LogGenericError(nullObjectName + " is null!", previousMethodName); |
| 82 | + } |
| 83 | + |
| 84 | + [Conditional("DEBUG")] |
| 85 | + internal static void LogGenericDebug(string message, [CallerMemberName] string previousMethodName = "") { |
| 86 | + if (string.IsNullOrEmpty(message)) { |
| 87 | + return; |
| 88 | + } |
| 89 | + |
| 90 | + MessageBox.Show(previousMethodName + "() " + message, "Debug", MessageBoxButtons.OK, MessageBoxIcon.Information); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments