tomchristie: This way around we'll get an error immediately if lifespan instantiation is not supported. That will gracefully disable it, and should resolve #222.
diff --git a/uvicorn/middleware/message_logger.py b/uvicorn/middleware/message_logger.py
index 3ddc9c9..a33736d 100644
--- a/uvicorn/middleware/message_logger.py
+++ b/uvicorn/middleware/message_logger.py
@@ -36,20 +36,27 @@ class MessageLoggerMiddleware:
 class MessageLoggerResponder:
     def __init__(self, scope, app, logger, task_counter):
         self.scope = scope
-        self.app = app
         self.logger = logger
         self.task_counter = task_counter
         self.client_addr = scope.get('client')
 
+        logged_scope = message_with_placeholders(scope)
+        log_text = '%s - ASGI [%d] Initialized %s'
+        self.logger.debug(log_text, self.client_addr, self.task_counter, logged_scope)
+        try:
+            self.inner = app(scope)
+        except:
+            log_text = '%s - ASGI [%d] Raised exception'
+            self.logger.debug(log_text, self.client_addr, self.task_counter)
+            raise
+
     async def __call__(self, receive, send):
         self._receive = receive
         self._send = send
-        logged_scope = message_with_placeholders(self.scope)
-        log_text = '%s - ASGI [%d] Started %s'
-        self.logger.debug(log_text, self.client_addr, self.task_counter, logged_scope)
+        log_text = '%s - ASGI [%d] Started task'
+        self.logger.debug(log_text, self.client_addr, self.task_counter)
         try:
-            inner = self.app(self.scope)
-            await inner(self.receive, self.send)
+            await self.inner(self.receive, self.send)
         except:
             log_text = '%s - ASGI [%d] Raised exception'
             self.logger.debug(log_text, self.client_addr, self.task_counter)

Error integrating with Channels if 'lifespan' is not specified in router
I'm not entirely sure if I should be posting this here or on `channels`.

I'm using v0.3.12 which I believe has already introduced the new `lifespan` protocol defined in asgiref. But this causes an error with `channels`' router

```bash
Traceback (most recent call last):
   File "/usr/local/lib/python3.6/site-packages/uvicorn/lifespan.py", line 29, in run
     await self.asgi(self.receive, self.send)
   File "/usr/local/lib/python3.6/site-packages/uvicorn/middleware/message_logger.py", line 51, in __call__
     inner = self.app(self.scope)
   File "/usr/local/lib/python3.6/site-packages/channels/routing.py", line 58, in __call__
     raise ValueError("No application configured for scope type %r" % scope["type"])
ValueError: No application configured for scope type 'lifespan'
```

My `routing.py` file looks like this:

```python
application = ProtocolTypeRouter({
    # Empty for now (http->django views is added by default)
    'websocket': JWTWebsocketMiddleware(
        URLRouter(urlpatterns)
    )
})
```

**EDIT**: Sorry my workaround wasn't actually working as you'll need at least one `path` in the `URLRouter`, so I've removed it.

To temporarily get around this, I had to downgrade to `v0.3.9`.
diff --git a/tests/middleware/test_message_logger.py b/tests/middleware/test_message_logger.py
index 2541dc0..1d07ed6 100644
--- a/tests/middleware/test_message_logger.py
+++ b/tests/middleware/test_message_logger.py
@@ -19,7 +19,8 @@ def test_message_logger(caplog):
     response = client.get("/")
     assert response.status_code == 200
     messages = [record.msg % record.args for record in caplog.records]
-    assert sum(['ASGI [1] Started' in message for message in messages]) == 1
+    assert sum(['ASGI [1] Initialized' in message for message in messages]) == 1
+    assert sum(['ASGI [1] Started task' in message for message in messages]) == 1
     assert sum(['ASGI [1] Sent' in message for message in messages]) == 1
     assert sum(['ASGI [1] Received' in message for message in messages]) == 2
     assert sum(['ASGI [1] Completed' in message for message in messages]) == 1
@@ -39,7 +40,26 @@ def test_message_logger_exc(caplog):
     with pytest.raises(RuntimeError):
         client.get("/")
     messages = [record.msg % record.args for record in caplog.records]
-    assert sum(['ASGI [1] Started' in message for message in messages]) == 1
+    assert sum(['ASGI [1] Initialized' in message for message in messages]) == 1
+    assert sum(['ASGI [1] Started task' in message for message in messages]) == 1
+    assert sum(['ASGI [1] Sent' in message for message in messages]) == 0
+    assert sum(['ASGI [1] Received' in message for message in messages]) == 0
+    assert sum(['ASGI [1] Completed' in message for message in messages]) == 0
+    assert sum(['ASGI [1] Raised exception' in message for message in messages]) == 1
+
+
+def test_message_logger_scope_exc(caplog):
+    def app(scope):
+        raise RuntimeError()
+
+    caplog.set_level(logging.DEBUG)
+    app = MessageLoggerMiddleware(app)
+    client = TestClient(app)
+    with pytest.raises(RuntimeError):
+        client.get("/")
+    messages = [record.msg % record.args for record in caplog.records]
+    assert sum(['ASGI [1] Initialized' in message for message in messages]) == 1
+    assert sum(['ASGI [1] Started task' in message for message in messages]) == 0
     assert sum(['ASGI [1] Sent' in message for message in messages]) == 0
     assert sum(['ASGI [1] Received' in message for message in messages]) == 0
     assert sum(['ASGI [1] Completed' in message for message in messages]) == 0

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov requests codecov
3.6
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
certifi==2021.5.30
charset-normalizer==2.0.12
click==8.0.4
codecov==2.1.13
coverage==6.2
dataclasses==0.8
h11==0.13.0
httptools==0.6.0
idna==3.10
importlib-metadata==4.8.3
iniconfig==1.1.1
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.1.4
pytest==7.0.1
pytest-cov==4.0.0
requests==2.27.1
tomli==1.2.3
typing_extensions==4.1.1
urllib3==1.26.20
-e git+https://github.com/encode/uvicorn.git@21494a0e7b4a063793ec1165c9e94b2c09ead2aa#egg=uvicorn
uvloop==0.14.0
websockets==9.1
wsproto==1.0.0
zipp==3.6.0

name: uvicorn
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - charset-normalizer==2.0.12
      - click==8.0.4
      - codecov==2.1.13
      - coverage==6.2
      - dataclasses==0.8
      - h11==0.13.0
      - httptools==0.6.0
      - idna==3.10
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pytest-cov==4.0.0
      - requests==2.27.1
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - uvloop==0.14.0
      - websockets==9.1
      - wsproto==1.0.0
      - zipp==3.6.0
prefix: /opt/conda/envs/uvicorn

tests/middleware/test_message_logger.py::test_message_logger tests/middleware/test_message_logger.py::test_message_logger_exc tests/middleware/test_message_logger.py::test_message_logger_scope_exc
uvicorn/middleware/message_logger.py
uvicorn/middleware/message_logger.py