1+ using System ;
2+ using UnityEngine ;
3+
4+ namespace BetaHub
5+ {
6+ /// <summary>
7+ /// Interface for contextual diagnostics providing error handling and logging capabilities.
8+ /// </summary>
9+ public interface IContextualDiagnostics
10+ {
11+ /// <summary>
12+ /// Logs an informational message for an operation.
13+ /// </summary>
14+ void LogInfo ( string operation , string message ) ;
15+
16+ /// <summary>
17+ /// Logs a successful operation completion.
18+ /// </summary>
19+ void LogSuccess ( string operation , string message ) ;
20+
21+ /// <summary>
22+ /// Logs progress information for a long-running operation.
23+ /// </summary>
24+ void LogProgress ( string operation , string message ) ;
25+
26+ /// <summary>
27+ /// Logs an error with a custom message and exception details.
28+ /// </summary>
29+ void LogError ( string operation , string message , Exception ex = null ) ;
30+ }
31+
32+ /// <summary>
33+ /// Main entry point for BetaHub diagnostics.
34+ /// </summary>
35+ public static class BetaHubDiagnostics
36+ {
37+ /// <summary>
38+ /// Creates a contextual diagnostics service for a specific component or operation context.
39+ /// </summary>
40+ public static IContextualDiagnostics ForContext ( string contextName )
41+ {
42+ return new ContextualDiagnostics ( contextName ) ;
43+ }
44+ }
45+
46+ /// <summary>
47+ /// Implementation of contextual diagnostics that provides consistent logging.
48+ /// </summary>
49+ internal class ContextualDiagnostics : IContextualDiagnostics
50+ {
51+ private readonly string _contextName ;
52+
53+ public ContextualDiagnostics ( string contextName )
54+ {
55+ _contextName = contextName ?? throw new ArgumentNullException ( nameof ( contextName ) ) ;
56+ }
57+
58+ public void LogInfo ( string operation , string message )
59+ {
60+ Debug . Log ( $ "[INFO] { _contextName } .{ operation } : { message } ") ;
61+ }
62+
63+ public void LogSuccess ( string operation , string message )
64+ {
65+ Debug . Log ( $ "[SUCCESS] { _contextName } .{ operation } : { message } ") ;
66+ }
67+
68+ public void LogProgress ( string operation , string message )
69+ {
70+ Debug . Log ( $ "[PROGRESS] { _contextName } .{ operation } : { message } ") ;
71+ }
72+
73+ public void LogError ( string operation , string message , Exception ex = null )
74+ {
75+ string errorMessage = ex != null
76+ ? $ "[ERROR] { _contextName } .{ operation } : { message } - { ex . Message } \n { ex . StackTrace } "
77+ : $ "[ERROR] { _contextName } .{ operation } : { message } ";
78+ Debug . LogError ( errorMessage ) ;
79+ }
80+ }
81+ }
0 commit comments