Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / Common.Internal / MultimediaLog.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Diagnostics;
19 using System.Runtime.CompilerServices;
20 using System.Text;
21
22 namespace Tizen.Multimedia
23 {
24     internal static class MultimediaLog
25     {
26         [Conditional("DEBUG")]
27         public static void Debug(string tag, string message, Exception e = null, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
28         {
29             Log.Debug(tag, BuildMessage(message, e), file, func, line);
30         }
31
32         public static void Error(string tag, string message, Exception e = null, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
33         {
34             Log.Error(tag, BuildMessage(message, e), file, func, line);
35         }
36
37         public static void Fatal(string tag, string message, Exception e = null, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
38         {
39             Log.Fatal(tag, BuildMessage(message, e), file, func, line);
40         }
41
42         public static void Info(string tag, string message, Exception e = null, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
43         {
44             Log.Info(tag, BuildMessage(message, e), file, func, line);
45         }
46
47         public static void Verbose(string tag, string message, Exception e = null, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
48         {
49             Log.Verbose(tag, BuildMessage(message, e), file, func, line);
50         }
51
52         public static void Warn(string tag, string message, Exception e = null, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
53         {
54             Log.Warn(tag, BuildMessage(message, e), file, func, line);
55         }
56
57         private static string BuildMessage(string message, Exception exception)
58         {
59             if (exception == null)
60             {
61                 return message;
62             }
63
64             StringBuilder sb = new StringBuilder();
65
66             Exception e = exception;
67             while (e != null)
68             {
69                 message += e.Message + Environment.NewLine + e.StackTrace;
70                 e = e.InnerException;
71             }
72
73             return sb.ToString();
74         }
75     }
76 }