feat(maui): implement unified Serilog logging infrastructure and Blazor/JS interop bridge
This commit is contained in:
@@ -26,7 +26,53 @@
|
||||
|
||||
<script src="_framework/blazor.webview.js" autostart="false"></script>
|
||||
<script src="_content/NexusReader.UI.Shared/js/d3.v7.min.js"></script>
|
||||
<script>
|
||||
window.NexusLogging = {
|
||||
initializeBridge: function (dotNetHelper) {
|
||||
const originalLog = console.log;
|
||||
const originalWarn = console.warn;
|
||||
const originalError = console.error;
|
||||
|
||||
console.log = function (...args) {
|
||||
originalLog.apply(console, args);
|
||||
try {
|
||||
dotNetHelper.invokeMethodAsync('LogJsMessage', 'info', args.map(x => typeof x === 'object' ? JSON.stringify(x) : String(x)).join(' '));
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
console.warn = function (...args) {
|
||||
originalWarn.apply(console, args);
|
||||
try {
|
||||
dotNetHelper.invokeMethodAsync('LogJsMessage', 'warn', args.map(x => typeof x === 'object' ? JSON.stringify(x) : String(x)).join(' '));
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
console.error = function (...args) {
|
||||
originalError.apply(console, args);
|
||||
try {
|
||||
dotNetHelper.invokeMethodAsync('LogJsMessage', 'error', args.map(x => typeof x === 'object' ? JSON.stringify(x) : String(x)).join(' '));
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
window.onerror = function (message, source, lineno, colno, error) {
|
||||
const stack = error ? error.stack : '';
|
||||
try {
|
||||
dotNetHelper.invokeMethodAsync('LogJsMessage', 'error', `${message} at ${source}:${lineno}:${colno}`, stack);
|
||||
} catch (e) {}
|
||||
return false;
|
||||
};
|
||||
|
||||
window.addEventListener('unhandledrejection', function (event) {
|
||||
const reason = event.reason;
|
||||
const message = reason instanceof Error ? reason.message : String(reason);
|
||||
const stack = reason instanceof Error ? reason.stack : '';
|
||||
try {
|
||||
dotNetHelper.invokeMethodAsync('LogJsMessage', 'error', `Unhandled Promise Rejection: ${message}`, stack);
|
||||
} catch (e) {}
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user