Comments (5)
At the time the code runs, JSRuntime.Current
hasn't been initialized. We want to get in and set up logging early, since it means we can include exceptions generated during start-up in the log. Improvements welcome, though, if you spot any opportunities - thanks for checking it out!
from serilog-sinks-browserconsole.
Are multple MonoWebAssemblyJSRuntime
within one Blazor application officially supported?
I'm asking because as I said this seems to interfere with other interop calls. If you modify your example with the following:
Reference index.js
within index.html
with the following content:
window.exampleJsFunctions = {
showPrompt: function (text) {
return prompt(text, 'Type your name here');
}
};
Add this to Index.cshtml
:
@functions
{
protected override async Task OnInitAsync()
{
Console.WriteLine("OnInitAsync");
string s = await JSRuntime.Current.InvokeAsync<string>(
"exampleJsFunctions.showPrompt",
"Name");
Console.WriteLine(s);
}
}
You won't get any return value from showPrompt
😞
But as soon as you comment out the two Log calls in Main.cs
it works:
//Log.Debug("Hello, browser!");
//Log.Warning("Received strange response {@Response} from server", new { Username = "example", Cats = 7 });
from serilog-sinks-browserconsole.
What about making it possible (necessary) to inject the IJSRuntime
? Then you could do something like this:
public static void Main(string[] args)
{
SelfLog.Enable(m => Console.Error.WriteLine(m));
var monoWebAssemblyJsRuntime = new MonoWebAssemblyJSRuntime();
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.BrowserConsole(monoWebAssemblyJsRuntime)
.CreateLogger();
Log.Debug("Hello, browser!");
Log.Warning("Received strange response {@Response} from server", new { Username = "example", Cats = 7 });
try
{
CreateHostBuilder(args).ConfigureServices(x =>
{
x.AddSingleton<IJSRuntime>(monoWebAssemblyJsRuntime);
}).Build().Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "An exception occurred while creating the WASM host");
throw;
}
}
from serilog-sinks-browserconsole.
Interesting! I'm not knowledgeable enough to pick the right approach for Blazor here, might need some advice from @SteveSandersonMS 😊
from serilog-sinks-browserconsole.
#8 touches on this issue and has some details regarding the current state of Blazor, so closing this in favor of that one. Thanks!
from serilog-sinks-browserconsole.
Related Issues (9)
- Show time and source context in log messages HOT 1
- Dotnet 6 compatibility HOT 3
- Breaks a WASM .NET 7 app HOT 7
- Version 2.0.0 release plan HOT 3
- JSRuntime.InvokeAsync issue HOT 1
- `outputTemplate:` support HOT 5
- Adding serilog.sinks.browserconsole causes JsInterop to fail in Blazor WebAssembly. HOT 6
- browserconsole not working with .net5 blazor rc1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serilog-sinks-browserconsole.